:root {
    --bg: #1a1d24;
    --bg-2: #232730;
    --card: #2c313c;
    --line: #3a4050;
    --text: #e8eaf0;
    --text-dim: #9da3b1;
    --accent: #ffb74d;
    --accent-hover: #ffcb7d;
    --accent-soft: rgba(255, 183, 77, 0.18);
    --booked: #4a6f8a;
    --booked-soft: rgba(74, 111, 138, 0.35);
    --booked-text: #d8e8f5;
    --selecting: rgba(255, 183, 77, 0.45);
    --danger: #e57373;
    --success: #81c784;
    --slot-h: 28px;
    --time-col: 60px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    background: radial-gradient(ellipse at top, #2a2f3c 0%, var(--bg) 70%);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
}

header {
    text-align: center;
    padding: 20px 16px 8px;
}
header h1 {
    margin: 0; font-size: 26px;
    color: var(--accent);
}
.subtitle {
    margin: 6px 0 0; color: var(--text-dim); font-size: 14px;
}

.weeknav {
    display: flex; align-items: center; gap: 12px; justify-content: center;
    padding: 14px;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--line);
    background: rgba(0,0,0,0.15);
    backdrop-filter: blur(4px);
    position: sticky; top: 0; z-index: 5;
}
.weeknav button {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    transition: all 0.15s;
}
.weeknav button:hover { background: var(--accent-soft); border-color: var(--accent); }
.weeknav button:active { transform: translateY(1px); }
.weeknav button.today { font-size: 13px; }
.week-label {
    font-size: 16px; font-weight: 600;
    min-width: 220px;
    text-align: center;
}

main {
    padding: 16px;
    max-width: 1100px;
    margin: 0 auto;
}

.hint {
    color: var(--text-dim);
    font-size: 13px;
    text-align: center;
    margin-bottom: 12px;
}

.grid-wrap {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
}
.grid {
    display: grid;
    grid-template-columns: var(--time-col) repeat(7, 1fr);
    user-select: none;
    touch-action: none;
}

.grid > .day-head,
.grid > .time-head {
    background: var(--bg-2);
    padding: 8px 4px;
    text-align: center;
    font-size: 12px;
    color: var(--text-dim);
    border-bottom: 1px solid var(--line);
    border-right: 1px solid var(--line);
    position: sticky; top: 0; z-index: 2;
}
.grid > .day-head { font-weight: 600; color: var(--text); }
.grid > .day-head .date-num { display: block; font-size: 18px; font-weight: 700; color: var(--accent); margin-top: 2px; }
.grid > .day-head.is-today .date-num { color: var(--success); }
.grid > .day-head.is-today { background: rgba(129,199,132,0.08); }

.grid > .time-label {
    background: var(--bg-2);
    color: var(--text-dim);
    font-size: 11px;
    text-align: right;
    padding: 0 6px;
    line-height: var(--slot-h);
    border-right: 1px solid var(--line);
    border-bottom: 1px dashed rgba(58,64,80,0.5);
}
.grid > .time-label.hour-mark {
    border-bottom-style: solid;
    color: var(--text);
}

.cell {
    height: var(--slot-h);
    border-right: 1px solid var(--line);
    border-bottom: 1px dashed rgba(58,64,80,0.5);
    background: var(--bg-2);
    cursor: pointer;
    position: relative;
    transition: background-color 0.08s;
}
.cell.hour-mark { border-bottom-style: solid; }
.cell:hover:not(.booked):not(.past) { background: var(--accent-soft); }
.cell.past { background: #1d2027; cursor: not-allowed; opacity: 0.45; }
.cell.selecting:not(.booked) { background: var(--selecting) !important; }
.cell.booked {
    background: var(--booked-soft);
    color: var(--booked-text);
    font-size: 10px;
    overflow: hidden;
    line-height: 1.1;
    padding: 2px 4px;
}
.cell.booked.first {
    border-top: 2px solid var(--booked);
    padding-top: 1px;
}
.cell.booked .who {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}
.cell.booked .house {
    color: var(--text-dim);
    font-size: 9px;
    pointer-events: none;
}

/* ===== Modal ===== */
dialog {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--card);
    color: var(--text);
    padding: 0;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6);
    max-width: 420px;
    width: calc(100% - 32px);
}
dialog::backdrop { background: rgba(0,0,0,0.65); backdrop-filter: blur(2px); }
dialog form { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
dialog h2 { margin: 0; font-size: 18px; color: var(--accent); }
.modal-range { margin: 0; color: var(--text-dim); font-size: 13px; }
dialog label {
    display: flex; flex-direction: column; gap: 6px;
    font-size: 13px;
    color: var(--text-dim);
}
dialog input {
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
}
dialog input:focus { outline: none; border-color: var(--accent); }
dialog .actions {
    display: flex; gap: 8px; justify-content: flex-end;
    margin-top: 4px;
}
dialog button {
    padding: 10px 18px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--bg-2);
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
}
dialog button:hover { background: var(--card); }
dialog button.primary { background: var(--accent); color: #2a1f00; border-color: var(--accent); font-weight: 600; }
dialog button.primary:hover { background: var(--accent-hover); }
dialog button.danger { background: var(--danger); color: #4a0808; border-color: var(--danger); font-weight: 600; }
dialog button.danger:hover { background: #ef9a9a; }
.error {
    color: var(--danger);
    font-size: 13px;
    background: rgba(229,115,115,0.1);
    border: 1px solid rgba(229,115,115,0.4);
    border-radius: 8px;
    padding: 8px 10px;
}

footer {
    text-align: center;
    padding: 24px 16px 32px;
    color: var(--text-dim);
    font-size: 12px;
}

@media (max-width: 700px) {
    :root { --slot-h: 24px; --time-col: 48px; }
    header h1 { font-size: 20px; }
    .subtitle { font-size: 12px; }
    .week-label { font-size: 14px; min-width: 0; }
    .grid > .day-head { font-size: 10px; padding: 6px 2px; }
    .grid > .day-head .date-num { font-size: 14px; }
    .cell.booked { font-size: 9px; }
    .cell.booked .house { display: none; }
    .grid > .time-label { font-size: 10px; padding: 0 3px; }
}
