:root {
    --bg: #0b1220;
    --panel: #16233a;
    --panel-2: #1e3050;
    --line: #2a3f60;
    --line-strong: #4b6b96;
    --text: #e8eefb;
    --dim: #7f93b3;
    --accent: #38bdf8;
    --ok: #4ade80;
    --bad: #f87171;
    --given: #b9c9e3;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    background: radial-gradient(120% 90% at 50% 0%, #16233a 0%, var(--bg) 60%);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    display: flex;
    justify-content: center;
    padding: 16px 16px 32px;
}

.game {
    position: relative;
    width: 100%;
    max-width: 480px;
}

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

h1 {
    font-size: 1.3rem;
    letter-spacing: .04em;
    text-transform: uppercase;
    margin: 0;
}

h1::after {
    content: "";
    display: block;
    width: 42px;
    height: 3px;
    margin-top: 6px;
    border-radius: 2px;
    background: var(--accent);
}

.levels {
    display: flex;
    gap: 6px;
}

.chip {
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--dim);
    border-radius: 999px;
    padding: 6px 13px;
    font: inherit;
    font-size: .76rem;
    cursor: pointer;
}

.chip.is-on {
    background: var(--accent);
    border-color: var(--accent);
    color: #06121f;
    font-weight: 700;
}

.stats {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 0 0 12px;
    padding: 0;
}

.stats li {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 8px 6px;
    text-align: center;
}

.stats b {
    display: block;
    font-size: 1.05rem;
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
}

.stats span {
    display: block;
    font-size: .58rem;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--dim);
    margin-top: 3px;
}

/* ---- board ---- */
.board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    aspect-ratio: 1 / 1;
    width: 100%;
    background: var(--panel);
    border: 2px solid var(--line-strong);
    border-radius: 12px;
    overflow: hidden;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    font-size: clamp(1rem, 4.6vw, 1.5rem);
    font-variant-numeric: tabular-nums;
    color: var(--accent);
    cursor: pointer;
    transition: background .1s ease;
}

.cell:nth-child(9n) {
    border-right: none;
}

.cell:nth-child(n+73) {
    border-bottom: none;
}

.cell.c3 {
    border-right: 2px solid var(--line-strong);
}

.cell.r3 {
    border-bottom: 2px solid var(--line-strong);
}

.cell--given {
    color: var(--given);
    font-weight: 600;
}

.cell--peer {
    background: rgba(56, 189, 248, .07);
}

.cell--same {
    background: rgba(56, 189, 248, .16);
}

.cell--sel {
    background: rgba(56, 189, 248, .3);
    box-shadow: inset 0 0 0 2px var(--accent);
}

.cell--bad {
    color: var(--bad);
    background: rgba(248, 113, 113, .16);
}

.cell--bad.cell--sel {
    background: rgba(248, 113, 113, .3);
    box-shadow: inset 0 0 0 2px var(--bad);
}

/* pencil marks */
.marks {
    position: absolute;
    inset: 1px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    font-size: clamp(.42rem, 1.7vw, .58rem);
    line-height: 1;
    color: var(--dim);
    font-weight: 600;
}

.marks i {
    display: flex;
    align-items: center;
    justify-content: center;
    font-style: normal;
}

/* ---- number pad ---- */
.pad {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 6px;
    margin-top: 12px;
}

.pad button {
    position: relative;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    font: inherit;
    font-size: 1.05rem;
    font-weight: 600;
    padding: 11px 0 14px;
    cursor: pointer;
    font-variant-numeric: tabular-nums;
    transition: background .12s ease, border-color .12s ease;
}

.pad button:hover {
    background: #27405f;
    border-color: var(--accent);
}

.pad button.is-done {
    opacity: .32;
}

.pad button small {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 2px;
    font-size: .52rem;
    font-weight: 400;
    color: var(--dim);
    letter-spacing: .04em;
}

/* ---- actions ---- */
.actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.btn {
    flex: 1 1 0;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 8px;
    font: inherit;
    font-size: .8rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s ease, border-color .15s ease;
}

.btn:hover {
    background: var(--panel-2);
    border-color: var(--accent);
}

.btn[aria-pressed="true"] {
    background: var(--accent);
    border-color: var(--accent);
    color: #06121f;
    font-weight: 700;
}

.btn--primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #06121f;
    font-weight: 700;
}

.btn--primary:hover {
    background: #7dd3fc;
}

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

kbd {
    background: rgba(0, 0, 0, .28);
    border-radius: 4px;
    padding: 0 4px;
    font-size: .66rem;
    color: inherit;
    opacity: .75;
}

.hintline {
    margin: 12px 2px 0;
    font-size: .76rem;
    color: var(--dim);
    line-height: 1.55;
}

/* [hidden] loses to display:flex on the rule below, so restore it */
.over[hidden] {
    display: none;
}

.over {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
    background: rgba(11, 18, 32, .9);
    backdrop-filter: blur(3px);
    border-radius: 14px;
    padding: 20px;
    z-index: 5;
}

.over h2 {
    margin: 0;
    font-size: 1.5rem;
}

.over p {
    margin: 0 0 8px;
    color: var(--dim);
    font-size: .9rem;
    max-width: 30em;
    line-height: 1.6;
}

/* Arabic build: the board stays LTR (digits and columns read left to right),
   everything else mirrors. The rule is driven by the dir attribute. */
[dir="rtl"] .game__head,
[dir="rtl"] .hintline {
    text-align: right;
}

@media (max-width: 420px) {
    .stats b {
        font-size: .92rem;
    }

    .btn {
        font-size: .74rem;
        padding: 9px 6px;
    }
}
