@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;700&display=swap');

:root {
    --bg-color: #1a1a1a;
    --text-color: #e0e0e0;
    --primary-color: #87ceeb;
    --card-bg-color: #2c2c2c;
    --border-color: #444;

    /* Scalable font sizes based on viewport width (for landscape) */
    --font-size-base: 1.2vw;
    --font-size-lg: 1.8vw;
    --font-size-xl: 3vw;
    --font-size-xxl: 5vw;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
    width: 100%;
    overflow: hidden; /* Prevents scrollbars on the page itself */
}

body {
    font-family: 'Noto Sans JP', 'Noto Color Emoji', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.aspect-ratio-wrapper {
    position: relative;
    width: 100vw;
    height: 56.25vw; /* 16:9 Aspect Ratio */
    max-height: 100vh;
    max-width: 177.78vh; /* 16:9 Aspect Ratio */
    background-color: var(--bg-color);
    overflow: hidden; /* Hide anything that overflows the wrapper */
}

.container {
    width: 100%;
    height: 100%;
    padding: 1.5vw; /* Use viewport width for padding */
    display: grid;
    grid-template-rows: auto 1fr; /* Header and main content */
    gap: 1.5vw;
}

.header {
    background-color: var(--card-bg-color);
    padding: 1vw 1.5vw;
    border-radius: 0.8vw;
    border: 0.1vw solid var(--border-color);
    text-align: center;
}

#date-time {
    display: flex;
    justify-content: center;
    align-items: baseline;
    gap: 1.5vw;
}

#date {
    font-size: var(--font-size-xl);
    font-weight: 700;
}

#time {
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--primary-color);
    letter-spacing: 0.1vw;
}

.main-content {
    display: grid;
    grid-template-columns: 2fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 1.5vw;
    overflow: hidden;
}

section {
    background-color: var(--card-bg-color);
    padding: 1vw 1.5vw;
    border-radius: 0.8vw;
    border: 0.1vw solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

h2, h3 {
    margin-bottom: 0.8vw;
    color: var(--primary-color);
    border-bottom: 0.15vw solid var(--border-color);
    padding-bottom: 0.4vw;
    font-size: var(--font-size-lg);
}

.weather-info {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
}

.tide-info {
    grid-column: 1 / 2;
    grid-row: 2 / 3;
}

.side-info {
    grid-column: 2 / 3;
    grid-row: 1 / 3;
    display: grid; /* Use Grid for strict row control */
    grid-template-rows: 1fr 1fr; /* Two equal rows */
    gap: 1.5vw;
    background: none;
    border: none;
    padding: 0;
}

.sun-info, .moon-info {
    background-color: var(--card-bg-color);
    padding: 1vw 1.5vw;
    border-radius: 0.8vw;
    border: 0.1vw solid var(--border-color);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

#weather {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(1, 1fr);
    text-align: center;
    gap: 0.8vw;
    flex-grow: 1;
    align-items: center;
}

.weather-hour {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3vw;
    font-size: var(--font-size-base);
}

.weather-hour .icon {
    font-size: 3vw;
}

#sunrise-sunset {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    width: 100%;
}

.sun-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5vw;
}

.sun-icon {
    font-size: 3.5vw;
}

.sun-label {
    font-size: var(--font-size-lg);
    font-weight: bold;
}

.sun-time {
    font-size: 2.8vw;
    font-weight: bold;
    color: var(--primary-color);
}

#moon-phase {
    font-weight: bold;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 0.5vw;
}

.moon-icon {
    font-size: 6vw;
}

.moon-name {
    font-size: var(--font-size-lg);
}

#tide-graph {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    overflow: hidden;
}

#tide-chart {
    flex-grow: 1;
}

.tide-summary {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5vw 1vw;
    margin-top: 0.5vw;
    font-size: var(--font-size-base);
    padding-top: 0.5vw;
    border-top: 0.1vw solid var(--border-color);
}

.tide-row {
    display: flex;
    justify-content: space-between;
}

.tide-row .tide-time {
    font-weight: bold;
}

/* ========== Mobile Responsive Styles (Portrait) ========== */
@media (orientation: portrait) {
    :root {
        /* Base font sizes on viewport height for portrait mode */
        --font-size-base: 2vh;
        --font-size-lg: 2.5vh;
        --font-size-xl: 5vh;
        --font-size-xxl: 7vh;
    }

    .aspect-ratio-wrapper {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
    }

    .container {
        padding: 2vh;
        gap: 2vh;
    }

    .header {
        padding: 1.5vh;
    }

    #date-time {
        flex-direction: column; /* Stack date and time */
        gap: 0.5vh;
    }

    .main-content {
        grid-template-columns: 1fr; /* Single column */
        grid-template-rows: auto auto auto; /* Let rows size automatically */
        gap: 2vh;
    }

    section {
        padding: 1.5vh;
    }
    
    h2, h3 {
        font-size: var(--font-size-lg);
    }

    .weather-info, .tide-info, .side-info {
        grid-column: auto;
        grid-row: auto;
    }
    
    .weather-info {
        min-height: 25vh;
    }

    .tide-info {
        min-height: 30vh;
    }

    #weather {
        grid-template-columns: repeat(4, 1fr); /* 4x2 grid for mobile */
        grid-template-rows: repeat(2, 1fr); /* 2行に変更 */
    }

    .weather-hour .icon {
        font-size: 5vh;
    }
    
    .side-info {
        display: grid;
        grid-template-columns: 1fr 1fr; /* Side by side for sun and moon */
        grid-template-rows: 1fr; /* single row */
        gap: 2vh;
    }
    
    .sun-info, .moon-info {
        padding: 1.5vh;
    }

    #sunrise-sunset {
        flex-direction: column; /* Stack sunrise and sunset */
        gap: 1.5vh;
    }

    .sun-icon {
        font-size: 4vh;
    }

    .sun-time {
        font-size: 3vh;
    }

    .moon-icon {
        font-size: 8vh;
    }
    
    .moon-name {
        font-size: 2.2vh;
    }

    .tide-summary {
        grid-template-columns: repeat(2, 1fr);
    }
}
.tide-name {
    color: var(--text-color);
    font-size: var(--font-size-lg);
    margin-left: 1vw;
}

/* ========== Mobile Responsive Styles (Specific for small screens) ========== */
@media (max-width: 600px) {
    /* --- Header Date/Time Font Size Adjustment --- */
    #date-time {
        flex-direction: row; /* Ensure it stays in a row */
        align-items: baseline;
    }

    #date, #time {
        font-size: 3vw; /* Further reduce font size for smaller screens */
    }

    /* --- Adjust vertical spacing for sections --- */
    .main-content {
        grid-template-rows: auto auto 1.5fr; /* Weather, Side, Tide */
    }

    .weather-info {
        min-height: 25vh; /* Restore weather height */
    }

    .sun-item {
        flex-direction: row;
        align-items: baseline;
        gap: 1.5vw;
    }

    .side-info {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto; /* Allow content to dictate height */
        gap: 1vh; /* Reduce gap */
    }

    .sun-info, .moon-info {
        padding: 1vh 1.5vh; /* Reduce padding */
    }

    .sun-icon {
        font-size: 3.5vh; /* Adjust icon size */
    }

    .sun-time {
        font-size: 2.5vh; /* Adjust time font size */
    }

    .moon-icon {
        font-size: 6vh; /* Adjust icon size */
    }

    .moon-name {
        font-size: 2vh; /* Adjust name font size */
    }

    .tide-info {
        min-height: 40vh; /* Increase tide chart height */
    }

    /* --- Weather Info Display Adjustment (Show only 4 hours) --- */
    #weather {
        grid-template-columns: repeat(4, 1fr) !important; /* Adjust grid to 4 columns */
        grid-template-rows: 1fr !important; /* Ensure it's a single row */
    }

    .weather-hour:nth-child(n+5) {
        display: none; /* Hide the 5th, 6th, 7th, 8th items */
    }
}

