/* ==========================================================================
   Shih Dao - frontend styles
   Colours prefixed with --c- are also read by sd.js to paint the canvas.
   ========================================================================== */

:root {
    color-scheme: light;

    --tile-0: #ee8577;
    --tile-1: #8fd19e;
    --tile-2: #6fa8f0;
    --tile-3: #b790ee;
    --tile-4: #f4d35e;
    --tile-5: #d6d3cc;

    --bg: #dfe3e8;
    --surface: #f5f6f8;
    --surface-2: #e9ecf0;
    --line: #c9cfd8;
    --ink: #1d2230;
    --ink-soft: #596175;
    --accent: #384a9c;
    --accent-ink: #ffffff;
    --accent-soft: rgba(56, 74, 156, .12);
    --danger: #a3302f;

    --c-board: #fbfbfc;
    --c-board-edge: #bcc3ce;
    --c-grid: #dde1e7;
    --c-watermark: rgba(36, 44, 66, .06);
    --c-hint-fill: rgba(56, 74, 156, .09);
    --c-hint-fill-strong: rgba(56, 74, 156, .26);
    --c-hint: #384a9c;
    --c-accent: #384a9c;
    --c-panel: #f5f6f8;
    --c-panel-edge: #c9cfd8;
    --c-text: #1d2230;
    --c-text-soft: #667088;

    --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}

:root[data-theme="dark"] {
    color-scheme: dark;

    --bg: #0f1218;
    --surface: #1a1e27;
    --surface-2: #232834;
    --line: #333a49;
    --ink: #e7eaf1;
    --ink-soft: #9aa3b8;
    --accent: #9db0f4;
    --accent-ink: #11152a;
    --accent-soft: rgba(157, 176, 244, .16);
    --danger: #f08a86;

    --c-board: #1c212b;
    --c-board-edge: #384052;
    --c-grid: #2a3040;
    --c-watermark: rgba(214, 224, 255, .055);
    --c-hint-fill: rgba(157, 176, 244, .10);
    --c-hint-fill-strong: rgba(157, 176, 244, .30);
    --c-hint: #9db0f4;
    --c-accent: #9db0f4;
    --c-panel: #1a1e27;
    --c-panel-edge: #333a49;
    --c-text: #e7eaf1;
    --c-text-soft: #98a1b6;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--ink);
    font: 16px/1.5 var(--font-ui);
    -webkit-text-size-adjust: 100%;
}

body { transition: background-color .2s ease; }

/* ---- layout ------------------------------------------------------------ */

.app {
    max-width: 1180px;
    margin: 0 auto;
    padding: 14px 16px 28px;
}

.bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
    font-weight: 400;
}

.brand .brand-mark {
    width: 74px;
    height: 37px;
    color: var(--ink);
}

.brand-name {
    font: 600 1.35rem/1 var(--font-display);
    letter-spacing: .01em;
}

.actions {
    display: flex;
    gap: 8px;
}

.stage {
    width: 100%;
    line-height: 0;
}

#board {
    display: block;
    width: 100%;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* ---- buttons ----------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--ink);
    font: 500 .9rem/1 var(--font-ui);
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease;
}

.btn:hover { background: var(--surface-2); border-color: var(--ink-soft); }
.btn:focus-visible, .close:focus-visible, .name-field input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.btn-icon { width: 40px; padding: 0; }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}
.btn-primary:hover { background: var(--accent); border-color: var(--accent); filter: brightness(1.08); }

.btn[disabled] { opacity: .55; cursor: default; }

/* theme button shows the icon of the theme it switches to */
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }

/* ---- glyph images (masked so they follow the text colour) -------------- */

.glyph {
    display: inline-block;
    width: 1em;
    height: 1em;
    background: currentColor;
    vertical-align: -.14em;
    -webkit-mask: var(--g) center / contain no-repeat;
    mask: var(--g) center / contain no-repeat;
}

/* ---- modals ------------------------------------------------------------ */

.modal {
    width: min(460px, calc(100vw - 24px));
    max-height: calc(100vh - 24px);
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 24px 60px rgba(8, 10, 18, .35);
}

.modal-wide { width: min(640px, calc(100vw - 24px)); }

.modal::backdrop {
    background: rgba(10, 13, 22, .55);
    backdrop-filter: blur(2px);
}

.modal[open] { animation: modal-in .18s ease-out; }

@keyframes modal-in {
    from { opacity: 0; transform: translateY(8px) scale(.985); }
    to   { opacity: 1; transform: none; }
}

.modal-inner {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 35px);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 22px 8px;
}

.modal-head h2 {
    margin: 0;
    font: 600 1.4rem/1.2 var(--font-display);
}

.close {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--ink-soft);
    font-size: 1.7rem;
    line-height: 1;
    cursor: pointer;
}
.close:hover { background: var(--surface-2); color: var(--ink); }

.modal-body {
    padding: 4px 22px 14px;
    overflow-y: auto;
}

.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 22px 18px;
    border-top: 1px solid var(--line);
}

.modal-body p { margin: 0 0 12px; text-align: justify; }
.modal-body p.tight { margin-bottom: 6px; }

.rules h3 {
    margin: 20px 0 6px;
    font: 600 1.05rem/1.3 var(--font-display);
}

.swatches {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 4px 0 6px;
}

.swatch {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    border: 1px solid rgba(0, 0, 0, .25);
}
.swatch.c0 { background: var(--tile-0); }
.swatch.c1 { background: var(--tile-1); }
.swatch.c2 { background: var(--tile-2); }
.swatch.c3 { background: var(--tile-3); }
.swatch.c4 { background: var(--tile-4); }
.swatch.c5 { background: var(--tile-5); }

.swatches .sep { width: 1px; height: 22px; margin: 0 6px; background: var(--line); }
.swatches .sym { font-size: 26px; }

.rule-table {
    width: 100%;
    margin: 0 0 8px;
    border-collapse: collapse;
}
.rule-table th, .rule-table td {
    padding: 9px 0;
    border-top: 1px solid var(--line);
    vertical-align: middle;
    text-align: left;
}
.rule-table th { width: 56px; font-size: 1.5rem; font-weight: 400; line-height: 1; }
.rule-table tr:last-child th, .rule-table tr:last-child td { border-bottom: 1px solid var(--line); }

/* ---- high scores ------------------------------------------------------- */

.result {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 16px;
    margin: 0 0 14px;
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--surface-2);
}
.result[hidden], .note[hidden] { display: none; }
.result strong { font: 600 1.05rem/1.3 var(--font-display); }
.result .tally { display: flex; gap: 14px; margin-left: auto; font-variant-numeric: tabular-nums; }
.result .tally span { display: inline-flex; align-items: center; gap: 5px; }
.result .tally .glyph { font-size: 1.25rem; }

.note {
    margin: 0 0 12px;
    color: var(--ink-soft);
}
.note.error { color: var(--danger); }

.scores-wrap { overflow-x: auto; }

.scores {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.scores th, .scores td {
    padding: 8px 8px;
    border-bottom: 1px solid var(--line);
    text-align: right;
    white-space: nowrap;
}

.scores th { font-weight: 500; color: var(--ink-soft); font-size: .85rem; }
.scores th .glyph { font-size: 1.35rem; color: var(--ink); }
.scores .pos { width: 40px; text-align: left; color: var(--ink-soft); }
.scores .name { width: 100%; max-width: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; }
.scores .date { color: var(--ink-soft); font-size: .85rem; }
.scores .anon { color: var(--ink-soft); font-style: italic; }

.scores tr.me td { background: var(--accent-soft); }
.scores tr.me td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

.name-field {
    display: flex;
    gap: 6px;
    min-width: 230px;
}
.name-field input {
    flex: 1;
    min-width: 0;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--accent);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    font: 1rem var(--font-ui);
}
.name-field .btn { min-height: 36px; padding: 0 12px; }

.empty {
    padding: 22px 0;
    color: var(--ink-soft);
}

/* ---- small screens ----------------------------------------------------- */

@media (max-width: 640px) {
    .app { padding: 10px 10px 20px; }
    .brand .brand-mark { width: 58px; height: 29px; }
    .brand-name { font-size: 1.15rem; }
    .btn:not(.btn-icon) { padding: 0 11px; }
    .actions .btn span { display: none; }
    .actions .btn:not(.btn-icon) { width: 40px; padding: 0; }
    .modal-head { padding: 14px 16px 6px; }
    .modal-body { padding: 4px 16px 12px; }
    .modal-foot { padding: 10px 16px 14px; }
    .result .tally { margin-left: 0; }
    .scores .date { display: none; }
    .scores th, .scores td { padding: 8px 5px; }
    .scores .pos { width: 26px; }
    .scores .name.editing { min-width: 120px; max-width: none; padding: 8px 8px 8px 0; }
    .name-field { min-width: 0; flex-direction: column; }
    .name-field input { width: 100%; flex: 0 0 auto; }
    .name-field .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    .modal[open] { animation: none; }
    body, .btn { transition: none; }
}
