:root {
    --bg: #111;
    --panel: #161616;
    --ink: #eaeaea;
    --muted: #9aa3a7;
    --accent: #ff8a1f;
    --danger: #ff5a5a;

    --grid: #2a2a2a;
    --grid-strong: #3a3a3a;
    --cell-size: 54px;
    --cell-font: 26px;
    --radius: 14px;
    --shadow: 0 12px 30px rgba(0, 0, 0, .35);
}

* {
    box-sizing: border-box
}

html, body {
    height: 100%
}

html, body, table, button, select {
    font-family: Inter, system-ui, Segoe UI, Roboto, Helvetica, Arial, sans-serif
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
}

/* layout */
.app {
    max-width: 980px;
    margin: 0 auto;
    padding: 20px 16px 40px;
}

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

.topbar h1 {
    margin: 0;
    font-size: 24px;
    letter-spacing: .5px;
}

.topbar .brand {
    display: flex;
    align-items: center;
    gap: 10px
}

.topbar .brand img {
    display: block
}

.lang-switch select {
    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--grid-strong);
    border-radius: 10px;
    padding: 8px 10px;
}

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

.difficulty {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.chip {
    background: #151515;
    color: var(--ink);
    border: 1px solid var(--grid);
    padding: 8px 10px;
    border-radius: 999px;
    cursor: pointer;
}

.chip:hover {
    border-color: var(--grid-strong)
}

.chip.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent) inset
}

/* centered board & pad */
.board-wrap {
    display: flex;
    gap: 18px;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: wrap;
}

@media (max-width: 800px) {
    .board-wrap {
        justify-content: center
    }
}

/* board */
.board {
    border-collapse: collapse;
    margin: 0;
    width: calc(var(--cell-size) * 9 + 8px);
    max-width: 100%;
    background: var(--panel);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--grid-strong);
}

.board td {
    width: var(--cell-size);
    height: var(--cell-size);
    border: 1px solid var(--grid);
    padding: 0;
    position: relative;
    text-align: center;
    vertical-align: middle;
}

.board tr:nth-child(3n) td {
    border-bottom: 2px solid var(--grid-strong);
}

.board td:nth-child(3n) {
    border-right: 2px solid var(--grid-strong);
}

/* cell */
.cell {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    cursor: pointer;
    position: relative;
}

.cell .val {
    font-size: var(--cell-font);
    line-height: 1;
}

.cell.fixed .val {
    color: #ffb472;
    text-shadow: 0 0 6px rgba(255, 138, 31, .15);
}

/* value matches (ярче) */
.cell.match::after {
    content: '';
    position: absolute;
    inset: 2px;
    border-radius: 6px;
    background: rgba(255, 138, 31, .22);
    pointer-events: none;
}

/* note matches (мягче) */
.cell.note-hit::before {
    content: '';
    position: absolute;
    inset: 4px;
    border-radius: 6px;
    background: rgba(255, 138, 31, .12);
    pointer-events: none;
}

/* conflicts (красные оттенки, поверх всего) */
.cell.conflict::after {
    content: '';
    position: absolute;
    inset: 2px;
    border-radius: 6px;
    background: rgba(255, 90, 90, .28);
    outline: 1px solid rgba(255, 90, 90, .6);
    pointer-events: none;
}

/* notes */
.notes {
    position: absolute;
    inset: 4px;
    display: grid;
    grid-template-columns:repeat(3, 1fr);
    grid-template-rows:repeat(3, 1fr);
    gap: 2px;
    font-size: 10px;
    color: var(--muted);
    opacity: .95;
    pointer-events: none;
}

.notes span {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* note digit highlight */
.notes span.hit {
    color: var(--accent);
    font-weight: 600;
}

/* sidebar */
.sidebar {
    background: var(--panel);
    border: 1px solid var(--grid-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
    height: fit-content;
    min-width: 220px;
}

.numpad {
    display: grid;
    grid-template-columns:repeat(3, 1fr);
    gap: 8px;
}

/* numpad buttons */
.nkey {
    border: 1px solid var(--grid);
    background: #141414;
    border-radius: 12px;
    height: 48px;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--ink);
}

.nkey:hover {
    border-color: var(--grid-strong)
}

.nkey.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent) inset;
}

/* цифра «завершена» (все 9 расставлены) */
.nkey.complete {
    background: rgba(255, 138, 31, .15);
    box-shadow: 0 0 0 1px var(--accent) inset;
    opacity: .95;
}

.pad-extra {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

/* segmented toggle (3 кнопки) + радиусы углов */
.segmented {
    display: inline-flex;
    border: 1px solid var(--grid-strong);
    border-radius: 12px;
    overflow: hidden;
    background: #141414;
}

.seg-btn {
    padding: 10px 14px;
    border: 0;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    line-height: 1;
}

.seg-btn[aria-pressed="true"] {
    background: rgba(255, 138, 31, .15);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.seg-btn + .seg-btn {
    border-left: 1px solid var(--grid-strong);
}

.seg-btn:first-child {
    border-radius: 12px 0 0 12px;
}

.seg-btn:last-child {
    border-radius: 0 12px 12px 0;
}

/* legend */
.legend {
    margin-top: 14px;
    display: grid;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px
}

.swatch {
    width: 18px;
    height: 18px;
    border-radius: 6px;
    border: 1px solid var(--grid);
    display: inline-block;
    background: #141414;
}

.swatch.match {
    background: rgba(255, 138, 31, .22)
}

.swatch.fixed {
    background: #3a2b1f
}

/* buttons */
.btn {
    background: linear-gradient(180deg, #1a1a1a, #141414);
    border: 1px solid var(--grid-strong);
    color: var(--ink);
    padding: 10px 16px;
    border-radius: 12px;
    cursor: pointer;
}

.btn:hover {
    border-color: var(--accent)
}

.btn:active {
    transform: translateY(1px)
}

.btn-small {
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 14px
}

/* win overlay */
.win-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.win-overlay[hidden] {
    display: none !important;
}

.win-card {
    background: #161616;
    border: 1px solid var(--grid-strong);
    border-radius: 16px;
    padding: 18px 20px;
    min-width: 260px;
    text-align: center;
    box-shadow: var(--shadow);
}

.win-title {
    margin: 0 0 12px 0
}

/* a11y */
.sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.pad-head {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 6px 10px;
    background: #161616;
    border: 1px solid #2a2a2a;
    border-radius: 10px;
}

.pad-head .timer {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: #ff8a1f;
}

.pad-head .timer-icon {
    opacity: .85;
}
