/* --- CORE VARIABLES --- */
:root {
    --bg: #0f172a;
    --panel: #111827;
    --muted: #94a3b8;
    --ok: #22c55e;
    --warn: #f59e0b;
    --danger: #ef4444;
    --accent: #38bdf8;
    --break-color: #10b981;
}

/* --- LAYOUT & SCROLLING --- */
html {
    background-color: #0b1220;
    min-height: 100%;
}

body {
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
    background: linear-gradient(180deg, #0b1220, #0f172a);
    color: #e5e7eb;
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    box-sizing: border-box;
}

.app {
    width: 100%;
    height: auto;
    min-height: 100%;
    max-width: 100%;
    margin: 0;
    background: #0b1220cc;
    backdrop-filter: blur(6px);
    border-radius: 14px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    transition: all 0.3s ease;
    position: relative;
    overflow: visible;
}

/* --- HEADER & CONTROLS --- */
header {
    display: flex;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    margin-bottom: 16px;
    background: #0b1220cc;
    backdrop-filter: blur(6px);
    padding-top: 8px;
    z-index: 10;
}

header h1 {
    font-size: 1.4rem;
    margin: 0;
    font-weight: 600
}

.controls {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap
}

#settingsPanel {
    display: none;
    flex-direction: column;
    gap: 12px;
    background: #1e293b;
    padding: 15px;
    border-radius: 10px;
    border: 1px solid #334155;
    position: absolute;
    top: 60px;
    right: 20px;
    z-index: 20;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
    min-width: 280px;
}

#settingsPanel.show {
    display: flex;
}

button,
select,
input[type="time"] {
    background: #1e293b;
    color: #e5e7eb;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    touch-action: manipulation;
    cursor: pointer;
}

button:active {
    background: #334155
}

.primary-btn {
    background: var(--accent);
    color: #0f172a;
    font-weight: bold;
    border: none;
}

.danger-btn {
    background: #7f1d1d;
    color: #fecaca;
    border: 1px solid #991b1b;
}

#autoSetBtn {
    background-color: var(--ok);
    color: #052e16;
    font-weight: bold;
    border: none;
    width: 100%;
    margin-bottom: 8px;
    transition: 0.3s;
}

#autoSetBtn.active-auto {
    background-color: #475569;
    color: #94a3b8;
    cursor: default;
    pointer-events: none;
}

.sync-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
}

.sync-group button {
    padding: 4px 8px;
    font-size: 12px;
    flex: 1;
}

.offset-display {
    font-family: monospace;
    font-size: 12px;
    color: var(--accent);
    min-width: 40px;
    text-align: center;
}

.test-group {
    display: flex;
    gap: 8px;
}

.test-group input {
    flex: 1;
    background: #0f172a;
    color: white;
}

/* --- GRID & CARDS --- */
.grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    flex: 1
}

@media (min-width: 800px) {
    .grid {
        grid-template-columns: repeat(3, 1fr)
    }
}

.card {
    background: #0b1220;
    border: 1px solid #1f2937;
    border-radius: 12px;
    padding: 18px;
    transition: border-color 0.3s;
}

.header-card-layout {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 16px;
    align-items: start;
    margin-bottom: 8px;
}

.label {
    color: var(--muted);
    font-size: 14px;
    letter-spacing: .04em;
    text-transform: uppercase;
    margin-bottom: 6px;
    line-height: 1.4;
    display: block;
}

.value {
    font-size: 20px;
    font-weight: 600
}

.countdown {
    font-variant-numeric: tabular-nums;
    font-size: clamp(32px, 10vw, 56px);
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
    text-align: right;
}

/* --- PROGRESS BAR LAYOUT --- */
.progress-row {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 16px;
    width: 100%;
    border-top: 1px solid #1f2937;
    padding-top: 16px;
}

.progress-track {
    flex: 1;
    height: 24px;
    background: #1e293b;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.5s linear, background-color 0.3s ease;
    border-radius: 12px;
}

.progress-fill.danger {
    background: var(--danger);
}

.progress-fill.break {
    background: var(--break-color);
}

#progressPercent {
    font-size: 32px;
    color: #e5e7eb;
    font-weight: 800;
    font-family: inherit;
    line-height: 1;
    white-space: nowrap;
    min-width: 85px;
    text-align: right;
}

/* -------------------------------- */
.pill {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 14px;
    border: 1px solid #334155
}

.tomorrow-mode-text {
    color: var(--warn) !important;
    font-weight: bold;
}

.tomorrow-pill {
    border-color: var(--warn) !important;
    color: var(--warn) !important;
}

.status-break {
    color: var(--break-color);
    font-weight: 700;
}

.status-warn {
    color: var(--danger);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1
    }

    50% {
        opacity: 0.8
    }

    100% {
        opacity: 1
    }
}

/* --- SCHEDULE TABLE --- */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 15px;
    margin-top: 10px;
    table-layout: fixed;
}

th,
td {
    border-bottom: 1px solid #1f2937;
    padding: 12px 6px;
    vertical-align: middle;
}

th:nth-child(1),
td:nth-child(1) {
    width: 160px;
    color: var(--accent);
}

th:nth-child(2),
td:nth-child(2) {
    text-align: left;
}

th {
    color: #94a3b8;
    text-align: left;
    font-weight: 600;
    font-size: 13px
}

.time {
    color: #a5b4fc;
    white-space: nowrap
}

.subject {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.small {
    font-size: 13px
}

.row {
    display: flex;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap
}

.flexcol {
    display: flex;
    flex-direction: column;
    gap: 8px
}

.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.schedule-card {
    flex: none;
    display: flex;
    flex-direction: column;
    margin-top: 20px;
    max-height: none;
    height: auto;
}

.schedule-card>div:first-child {
    margin-bottom: 10px
}

.schedule-card>div:last-child {
    flex: 1;
    overflow: visible;
}

.edit-input {
    width: 100%;
    background: #0f172a;
    border: 1px solid #475569;
    color: white;
    padding: 4px;
    border-radius: 4px;
    font-size: 14px;
}

/* --- FULLSCREEN STYLES --- */
#fullscreenLayer {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 999;
    background: #0b1220;
    flex-direction: column;
    padding: env(safe-area-inset-top) 20px env(safe-area-inset-bottom) 20px;
}

#fullscreenLayer.active {
    display: flex;
}

.fs-section-top {
    flex: 60;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

.fs-section-bottom {
    flex: 40;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 0 40px;
    gap: 20px;
}

.fs-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    width: 100%;
}

.fs-clock {
    position: absolute;
    top: 10px;
    left: 10px;
    font-size: 18px;
    color: #64748b;
    font-weight: 500;
}

.fs-countdown {
    font-size: 28vh;
    font-weight: 900;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    text-align: center;
}

.fs-info-label {
    font-size: 13px;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 2px;
}

.fs-info-main {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    max-width: 90%;
}

.fs-info-sub {
    font-size: 20px;
    color: var(--muted);
    margin-top: 2px;
}

.fs-button {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 8px 16px;
    font-size: 16px;
    background: #334155;
    border: 1px solid #64748b;
    border-radius: 8px;
    cursor: pointer;
    z-index: 100;
}

/* NEW FULLSCREEN PROGRESS BAR */
.fs-progress-container {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 10px;
}

.fs-progress-track {
    flex: 1;
    height: 16px;
    background: #1e293b;
    border-radius: 8px;
    overflow: hidden;
}

.fs-progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    border-radius: 8px;
}

#fsProgressPercent {
    font-size: 24px;
    font-weight: 800;
    color: #94a3b8;
    font-variant-numeric: tabular-nums;
    min-width: 110px;
    text-align: right;
}

#testModeBadge {
    display: none;
    background: #ef4444;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: bold;
    margin-left: 8px;
    vertical-align: middle;
    text-transform: uppercase;
}