/* ---------- Themes (all text/background pairs are >= 7:1 contrast) ---------- */
:root, :root[data-theme="light"] {
    --bg: #ffffff;
    --fg: #000000;
    --line: #000000;
    --cell: #ffffff;
    --given-bg: #e4e4e4;
    --given-fg: #000000;
    --entry-fg: #0000d0;
    --peer-bg: #cfe0ff;
    --same-bg: #ffc766;
    --sel-bg: #ffe600;
    --sel-fg: #000000;
    --bad-bg: #c40000;
    --bad-fg: #ffffff;
    --btn-bg: #000000;
    --btn-fg: #ffffff;
    --btn-on-bg: #ffe600;
    --btn-on-fg: #000000;
    --panel: #ffffff;
}
:root[data-theme="dark"] {
    --bg: #000000;
    --fg: #ffffff;
    --line: #ffffff;
    --cell: #000000;
    --given-bg: #2e2e2e;
    --given-fg: #ffffff;
    --entry-fg: #ffe600;
    --peer-bg: #0c2f66;
    --same-bg: #7a4a00;
    --sel-bg: #4dd2ff;
    --sel-fg: #000000;
    --bad-bg: #ff5252;
    --bad-fg: #000000;
    --btn-bg: #ffffff;
    --btn-fg: #000000;
    --btn-on-bg: #ffe600;
    --btn-on-fg: #000000;
    --panel: #000000;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--fg);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Arial, sans-serif;
    font-weight: 700;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior: none;
    -webkit-user-select: none;
    user-select: none;
}

button {
    font: inherit;
    color: inherit;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
}

button:focus-visible, .app:focus-visible { outline: 5px solid #ff00ff; outline-offset: 2px; }
.app:focus { outline: none; }

/* ---------- Layout: always fits the visible screen, no scrolling ---------- */
.app {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: max(env(safe-area-inset-top), 8px) max(env(safe-area-inset-right), 8px)
             max(env(safe-area-inset-bottom), 8px) max(env(safe-area-inset-left), 8px);
    max-width: 820px;
    margin: 0 auto;
}

.topbar {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex: 0 0 auto;
}
.title { font-size: 24px; font-weight: 900; letter-spacing: .2px; }

.status {
    width: 100%;
    display: flex;
    justify-content: space-between;
    font-size: 20px;
    font-weight: 800;
    flex: 0 0 auto;
}

.board-wrap {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    container-type: size;
}

.board {
    width: min(100cqw, 100cqh);
    height: min(100cqw, 100cqh);
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    border: 5px solid var(--line);
    background: var(--line);
    container-type: inline-size;
}

.cell {
    appearance: none;
    -webkit-appearance: none;
    margin: 0;
    padding: 0;
    min-width: 0;
    min-height: 0;
    border: 1px solid var(--line);
    border-radius: 0;
    background: var(--cell);
    color: var(--entry-fg);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    font-size: 8.6cqw;
    font-weight: 900;
    line-height: 1;
}
.cell.br { border-right-width: 4px; }
.cell.bb { border-bottom-width: 4px; }

.cell.given { background: var(--given-bg); color: var(--given-fg); }
.cell.peer { background: var(--peer-bg); color: var(--fg); }
.cell.given.peer { color: var(--given-fg); }
.cell.entry.peer { color: var(--entry-fg); }
.cell.same { background: var(--same-bg); color: var(--fg); }
.cell.sel { background: var(--sel-bg); color: var(--sel-fg); }
.cell.bad { background: var(--bad-bg); color: var(--bad-fg); }
.cell.bad::after {            /* shape cue, so mistakes are not shown by colour alone */
    content: "";
    position: absolute; inset: 3px;
    border: 3px dashed var(--bad-fg);
    pointer-events: none;
}


.msg {
    flex: 0 0 auto;
    min-height: 26px;
    font-size: 19px;
    font-weight: 800;
    text-align: center;
}

/* ---------- Buttons ---------- */
.btn {
    background: var(--btn-bg);
    color: var(--btn-fg);
    border: 3px solid var(--line);
    border-radius: 12px;
    font-weight: 900;
}
.btn.on { background: var(--btn-on-bg); color: var(--btn-on-fg); }
.btn:disabled { opacity: .3; cursor: default; }

.numpad {
    width: 100%;
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}
.num {
    height: clamp(40px, 6dvh, 56px);
    font-size: clamp(26px, 7.5vw, 38px);
    line-height: 1;
    padding: 0;
}

/* Icon buttons: white symbols on strong colours (all >= 4.5:1), same in both themes */
.btn svg {
    width: clamp(26px, 7vw, 34px); height: clamp(26px, 7vw, 34px);
    fill: none; stroke: currentColor; stroke-width: 2.6;
    stroke-linecap: round; stroke-linejoin: round;
    display: block; margin: auto;
}
.btn.erase { background: #c40000; color: #fff; }
.btn.undo { background: #1b7a2b; color: #fff; }
.btn.new { background: #00727a; color: #fff; }
.btn.theme { background: #4a4a4a; color: #fff; }
.act.hint { background: #a84300; color: #fff; }
.act.check { background: #6a1b9a; color: #fff; }

.actions {
    width: 100%;
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}
.act {
    height: clamp(42px, 6dvh, 54px);
    padding: 0;
}

/* ---------- Menu / win overlay ---------- */
.overlay {
    position: fixed; inset: 0; z-index: 10;
    background: var(--bg);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 12px;
    padding: max(env(safe-area-inset-top), 16px) 16px max(env(safe-area-inset-bottom), 16px);
    overflow-y: auto;
}
.overlay h1 { font-size: 38px; margin: 0 0 4px; font-weight: 900; text-align: center; }
.overlay p { font-size: 22px; margin: 0; text-align: center; font-weight: 800; }
.menu-btn {
    width: min(100%, 460px);
    min-height: 68px;
    font-size: 28px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 8px 12px;
}
.menu-btn small { font-size: 17px; font-weight: 700; }
.menu-btn.cont { background: var(--btn-on-bg); color: var(--btn-on-fg); }
.hdr { font-size: 24px; font-weight: 900; margin-top: 6px; }

/* Short screens (iPhone SE, landscape) */
@media (max-height: 700px) {
    .title { font-size: 20px; }
    .status { font-size: 18px; }
    .msg { min-height: 22px; font-size: 17px; }
    .menu-btn { min-height: 58px; font-size: 24px; }
}

/* ---------- Loading + error UI ---------- */
.loading { height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.loading-title { font-size: 34px; font-weight: 900; }
.loading-progress-text { font-size: 24px; font-weight: 800; }
.loading-progress-text:after { content: var(--blazor-load-percentage-text, "Loading"); }

#blazor-error-ui {
    background: #ffe600; color: #000;
    bottom: 0; left: 0; right: 0; position: fixed;
    display: none; padding: 14px 20px; font-size: 20px; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 16px; top: 12px; font-size: 24px; }
