:root {
    --bg: #ffffff;
    --text: #1c1c1e;
    --sub-text: #8e8e93;
    --accent: #007aff;
    --danger: #ff3b30;
    --success: #34c759;
    --warning: #ffcc00;
    --card-bg: #f2f2f7;
    --border: #e5e5ea;
    --font-timer: 'Orbitron', 'Helvetica Neue', sans-serif;
}

@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@700&display=swap');

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    overflow: hidden;
    /* App-like feel */
}

/* 広告フッターエリア */
#sticky-ad-footer {
    flex-shrink: 0;
    width: 100%;
    background: #f8f8f8;
    z-index: 9000;
    min-height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
}

/* --- AdSense Stability --- */
button,
input,
.timer-display,
.menu-icon-btn {
    position: relative;
    z-index: 9005;
}

/* Ensure enough bottom spacing for Anchor Ads */
.dashboard-view {
    padding-bottom: 30px !important;
}

/* If there is a footer with controls */
footer,
.timer-controls {
    padding-bottom: 20px !important;
    background-color: transparent !important;
}

/* --- Layout --- */
#main-content-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

/* --- Menu Button (Floating) --- */
.menu-icon-btn {
    position: fixed;
    top: 30px;
    left: 15px;
    z-index: 9999;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #eee;
    padding: 10px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s;
    color: #333;
}

.menu-icon-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* --- Navigation Menu (Side) --- */
.nav-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100%;
    background: #fff;
    z-index: 2000;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.nav-menu.open {
    transform: translateX(0);
}

.nav-logo-area {
    padding: 40px 20px 20px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.nav-logo-area img {
    max-width: 140px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 18px 25px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    color: #555;
    transition: 0.2s;
}

.nav-icon {
    width: 24px;
    height: 24px;
    fill: #888;
    transition: 0.2s;
}

.nav-item:active {
    background: #f0f0f0;
    color: var(--accent);
}

.nav-item:active .nav-icon {
    fill: var(--accent);
}

/* --- Header --- */
.app-header {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 100;
    position: relative;
    border-bottom: 1px solid transparent;
    /* Prepare for scroll border */
}

.app-header h1 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.mode-icon-header {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.mode-icon-header svg {
    width: 24px;
    height: 24px;
    fill: var(--accent);
}

/* Default Icon Button (Transparent) - Keep for Settings etc if needed, or update ID specific */
.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Specific Style for Header Menu Button to match Floating Button */
#menuBtnHeader {
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #eee;
    padding: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    color: #333;
    width: 46px;
    /* Match floating size approx (24 + 10*2 padding + border) */
    height: 46px;
}

.icon-btn:active {
    background: var(--card-bg);
}

.icon-btn svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    fill: currentColor;
}

.header-right {
    display: flex;
    gap: 8px;
}

/* --- Dashboard View (Home) --- */
.dashboard-view {
    flex: 1;
    overflow-y: auto;
    padding: 80px 20px 40px;
    display: block;
    /* Changed from flex to block for scrolling */
}

.dashboard-title {
    text-align: center;
    font-size: 1.5rem;
    margin: 0 0 25px;
    color: var(--text);
    font-weight: bold;
    line-height: 1.4;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    /* Ensure readable font, not orbitron if default */
}

@media (max-width: 600px) {
    .dashboard-title {
        font-size: 1.2rem;
        margin-bottom: 20px;
    }

    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        /* Force 2 columns */
    }
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    /* Center the grid */
}

.dash-card {
    background: #fff;
    border-radius: 16px;
    padding: 20px 10px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 160px;
    height: auto;
}

.dash-card:active {
    transform: scale(0.98);
    background-color: var(--card-bg);
}

.dash-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
}

.dash-icon svg {
    width: 28px;
    height: 28px;
    fill: white;
}

/* Mobile Responsiveness for Dashboard */
@media (max-width: 600px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
        /* Single column on mobile */
        max-width: 100%;
    }

    .dash-card {
        flex-direction: column !important;
        min-height: auto;
        padding: 20px;
        align-items: center;
        text-align: center;
        height: auto;
    }

    .dash-icon {
        margin-bottom: 10px;
        margin-right: 0;
    }

    #mode0,
    .dashboard-view {
        padding-top: 80px !important;
    }
}

/* Icon Colors */
.dash-icon.up {
    background: #34c759;
}

.dash-icon.down {
    background: #ff9500;
}

.dash-icon.emom {
    background: #5856d6;
}

.dash-icon.tabata {
    background: #ff2d55;
}

.dash-card h2 {
    font-size: 1.1rem;
    margin: 0 0 5px;
    color: var(--text);
}

.dash-card p {
    font-size: 0.8rem;
    color: var(--sub-text);
    margin: 0;
}

/* --- Timer View --- */
.timer-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    padding-bottom: 30px;
    /* Space for controls */
}

#status-display {
    font-size: 1.2rem;
    color: var(--sub-text);
    margin-bottom: 1vh;
    font-weight: 500;
    min-height: 1.5em;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#timer-display {
    display: flex;
    align-items: baseline;
    justify-content: center;
    line-height: 0.9;
    font-variant-numeric: tabular-nums;
}

#timer-prefix {
    font-family: var(--font-timer);
    font-size: 14vw;
    color: var(--accent);
    margin-right: 2vw;
    opacity: 0.9;
}

#timer-main {
    font-family: var(--font-timer);
    font-size: 24vw;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -2px;
}

/* Clock Mode Reordering */
body.clock-mode #timer-prefix {
    order: 2;
    margin-right: 0;
    margin-left: 2vw;
    font-size: 12vw;
}

body.clock-mode #timer-main {
    order: 1;
}

/* --- Controls Footer --- */
.controls-footer {
    position: absolute;
    bottom: 20px;
    /* Reduced from 40px to accommodate ad */
    left: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    /* Stack ad and buttons */
    align-items: center;
    /* Center horizontally */
    justify-content: flex-end;
    /* Align to bottom */
    z-index: 100;
}

.controls-wrapper {
    display: flex;
    align-items: center;
    gap: 40px;
}

.ctrl-btn {
    border: none;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.1s, opacity 0.2s;
}

.ctrl-btn:active {
    transform: scale(0.95);
}

.ctrl-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.ctrl-btn .icon {
    /* font-size: 1.5rem; Removed for SVG */
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ctrl-btn .label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.ctrl-btn.secondary {
    width: 60px;
    height: 60px;
    background: var(--card-bg);
    color: var(--text);
}

.ctrl-btn.primary-play {
    width: 80px;
    height: 80px;
    background: var(--success);
    color: white;
    font-size: 1.2rem;
}

.ctrl-btn.primary-pause {
    width: 80px;
    height: 80px;
    background: var(--danger);
    color: white;
}

.ctrl-btn.primary-play .icon,
.ctrl-btn.primary-pause .icon {
    /* font-size: 2rem; Removed for SVG */
}


/* --- Settings Modal --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 3000;
    display: none;
    align-items: center;
    /* Changed to center */
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}

.settings-modal-content {
    background: var(--bg);
    width: 90%;
    /* Responsive width */
    max-width: 500px;
    border-radius: 20px;
    /* All corners */
    height: auto;
    max-height: 80vh;
    /* Max height instead of fixed */
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    /* More elevated shadow */
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (min-width: 600px) {
    .modal-overlay {
        align-items: center;
    }

    .settings-modal-content {
        border-radius: 20px;
        height: auto;
        max-height: 80vh;
    }
}

.modal-header {
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.1rem;
    margin: 0;
}

.close-icon {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--sub-text);
    cursor: pointer;
    line-height: 1;
}

.settings-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.setting-group {
    margin-bottom: 24px;
}

.setting-group h3 {
    font-size: 0.9rem;
    color: var(--sub-text);
    margin-bottom: 12px;
    text-transform: uppercase;
}

.input-row {
    display: flex;
    gap: 16px;
    margin-bottom: 8px;
}

.input-item {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.input-item label {
    font-size: 0.8rem;
    color: var(--sub-text);
    margin-top: 4px;
    text-align: center;
}

input[type="number"] {
    width: 100%;
    padding: 12px;
    font-size: 1.5rem;
    text-align: center;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--card-bg);
    color: var(--text);
    font-weight: bold;
    -webkit-appearance: none;
    appearance: none;
}

input[type="number"]:focus {
    outline: 2px solid var(--accent);
    border-color: transparent;
}

.full-width-btn {
    width: 100%;
    padding: 16px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #e4e4e4;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

input:checked+.slider {
    background-color: var(--success);
    /* Green for enabled */
}

input:checked+.slider:before {
    transform: translateX(22px);
}

/* --- State Styles --- */
/* Applied to body for full immersion */
body.state-work {
    background-color: #fff0f0;
}

/* Slight Red Tint for Work? Or Green? Tabata Work is usually High Intensity so Red? */
/* Actually standard CrossFit timers use Green for 'Go' (Work) and Red for 'Stop/Rest' often, or vice versa. 
   Let's stick to Green for Work (Go) and Red for Rest (Stop).
*/
body.state-work {
    background-color: #e8f5e9;
}

/* Light Green */
body.state-work #timer-main {
    color: #2e7d32;
}

body.state-rest {
    background-color: #ffebee;
}

/* Light Red */
body.state-rest #timer-main {
    color: #c62828;
}

body.state-prepare {
    background-color: #fffde7;
}

/* Light Yellow */
body.state-prepare #status-display {
    color: #f57f17;
    font-weight: bold;
}


/* --- Landscape Optimization (Mobile/Small Screens) --- */
@media (orientation: landscape) and (max-height: 600px) {
    .app-header {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        background: transparent;
        backdrop-filter: none;
        border: none;
        padding: 10px 20px;
    }

    .app-header h1 {
        display: none;
    }

    /* Hide title */

    .timer-view {
        padding-bottom: 0;
    }

    #timer-prefix {
        font-size: 10vw;
    }

    #timer-main {
        font-size: 26vw;
    }

    .controls-footer {
        bottom: 20px;
        opacity: 0.2;
        /* Fade out controls */
        transition: opacity 0.3s;
    }

    .controls-footer:hover,
    .controls-footer:active {
        opacity: 1;
    }

    .ctrl-btn {
        transform: scale(0.8);
    }

    /* Smaller controls */
}

/* --- Animations --- */
@keyframes slideUp {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.hidden {
    display: none !important;
}

/* --- Visual Cues --- */
@keyframes flashGreen {
    0% {
        background-color: var(--bg);
    }

    30% {
        background-color: #befbc8;
    }

    /* Light Green Flash */
    100% {
        background-color: var(--bg);
    }
}

@keyframes flashRed {
    0% {
        background-color: var(--bg);
    }

    30% {
        background-color: #ffcccb;
    }

    /* Light Red Flash */
    100% {
        background-color: var(--bg);
    }
}

.flash-start {
    animation: flashGreen 0.6s ease-out !important;
}

.flash-end {
    animation: flashRed 1.0s ease-in-out infinite !important;
}

/* --- PWA Promotion Banner --- */
.add-home-banner {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 400px;
    background: rgba(30, 30, 30, 0.95);
    color: white;
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: none;
    /* Initially hidden, shown by JS */
    align-items: center;
    justify-content: space-between;
    z-index: 5000;
    animation: slideUp 0.5s ease-out;
}

.add-home-text {
    flex: 1;
    font-size: 0.9rem;
    line-height: 1.3;
}

.add-home-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 0.85rem;
    margin-left: 10px;
    cursor: pointer;
}

.add-home-close {
    background: none;
    border: none;
    color: #999;
    font-size: 1.5rem;
    margin-left: 10px;
    cursor: pointer;
    line-height: 1;
}