.fs-page {
    --fs-ink: #182238;
    --fs-accent: #e8a93a;
    --fs-soft: #f4f7fb;
    width: calc(100% + 4rem);
    max-width: 1400px;
    margin: 0 -2rem;
    padding: clamp(12px, 2vw, 28px) max(8px, env(safe-area-inset-right)) clamp(40px, 6vw, 80px) max(8px, env(safe-area-inset-left));
    border-radius: 22px;
    background: #f7fbff;
    color: var(--fs-ink);
}

.fs-topbar { display: flex; align-items: center; gap: 18px; max-width: 1200px; margin: auto; }
.fs-back { font-weight: 700; text-decoration: none; }
.fs-title { margin: 0; font-size: clamp(25px, 3vw, 42px); }
.fs-subtitle { margin: 3px 0 0; color: #59677b; }
.fs-topbar > div { flex: 1; }

.fs-button,
.fs-select {
    min-height: 48px;
    padding: 9px 14px;
    border: 2px solid var(--fs-ink);
    border-radius: 12px;
    background: white;
    color: var(--fs-ink);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.fs-button:disabled,
.fs-select:disabled,
.fs-board button:disabled { cursor: not-allowed; opacity: .55; }
.fs-button:focus-visible,
.fs-select:focus-visible,
.fs-board button:focus-visible,
.fs-face-choice:focus-visible,
.fs-close:focus-visible { outline: 4px solid #f2c14e; outline-offset: 2px; }
.fs-status { min-height: 28px; margin: 18px 0; text-align: center; font-weight: 700; }

.fs-layout { display: flex; justify-content: center; align-items: flex-start; gap: clamp(18px, 3vw, 48px); }
.fs-stage { width: min(100%, 760px); }
.fs-board {
    display: grid;
    width: 100%;
    aspect-ratio: 1;
    grid-template-columns: repeat(9, 1fr);
    gap: 1px;
    overflow: hidden;
    border: 4px solid var(--fs-ink);
    border-radius: 10px;
    background: var(--fs-ink);
}
.fs-board button {
    position: relative;
    display: grid;
    min-width: 0;
    padding: 4px;
    place-items: center;
    border: 0;
    background: #fff;
    cursor: pointer;
    touch-action: manipulation;
}
.fs-board button:nth-child(3n) { border-right: 3px solid var(--fs-ink); }
.fs-board button:nth-child(9n) { border-right: 0; }
.fs-board button:nth-child(n + 19):nth-child(-n + 27),
.fs-board button:nth-child(n + 46):nth-child(-n + 54) { border-bottom: 3px solid var(--fs-ink); }
.fs-board button.fs-cell--given { background: #edf1f8; cursor: default; }
.fs-token {
    display: grid;
    width: clamp(30px, 7vw, 64px);
    height: clamp(30px, 7vw, 64px);
    place-items: center;
    overflow: hidden;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #e6a535;
    color: #172238;
    font-size: clamp(17px, 3vw, 30px);
    font-weight: 800;
}
.fs-token img { width: 100%; height: 100%; object-fit: cover; }
.fs-notes { display: grid; width: 100%; height: 100%; grid-template-columns: repeat(3, 1fr); place-items: center; font-size: clamp(9px, 1.5vw, 15px); font-weight: 800; }
.fs-cell--selected { box-shadow: inset 0 0 0 5px #f0a72c !important; }
.fs-cell--conflict { background: #ffe0db !important; }
.fs-cell--wrong { background: #fff0b9 !important; }

.fs-controls { display: grid; width: min(260px, 100%); gap: 12px; }
.fs-label { font-weight: 700; }
.fs-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }
.fs-help { line-height: 1.5; }

.fs-overlay,
.fs-complete,
.fs-fatal {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: grid;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    padding: calc(14px + env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    place-items: center;
    background: rgba(9, 18, 36, .74);
}
.fs-overlay[hidden],
.fs-complete[hidden],
.fs-fatal[hidden] { display: none; }
.fs-picker,
.fs-dialog {
    width: min(720px, calc(100vw - 24px));
    max-height: calc(100vh - 28px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    max-height: calc(100svh - 28px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    max-height: calc(100dvh - 28px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow: auto;
    padding: clamp(16px, 3vw, 30px);
    border-radius: 22px;
    background: #fff;
    box-shadow: 0 16px 60px #071024;
    overscroll-behavior: contain;
}
.fs-picker-head { display: flex; align-items: center; gap: 12px; }
.fs-picker-head h2 { flex: 1; margin: 0; font-size: clamp(23px, 3vw, 34px); }
.fs-close { min-width: 110px; min-height: 52px; border: 2px solid var(--fs-ink); border-radius: 12px; background: #f6c557; color: var(--fs-ink); font-size: 18px; font-weight: 800; cursor: pointer; }
.fs-picker p { margin: 8px 0 14px; }
.fs-face-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.fs-face-choice { min-height: 140px; padding: 8px; border: 2px solid #c6cfdd; border-radius: 16px; background: var(--fs-soft); color: var(--fs-ink); font: inherit; font-weight: 700; cursor: pointer; }
.fs-face-choice:hover { border-color: var(--fs-accent); }
.fs-face-choice .fs-token { width: clamp(88px, 10vw, 108px); height: clamp(88px, 10vw, 108px); margin: 0 auto 5px; }
.fs-face-choice small { display: block; font-weight: 500; }
.fs-dialog { width: min(500px, 94vw); text-align: center; }

@media (max-width: 900px) {
    .fs-layout { display: block; }
    .fs-stage { margin: auto; }
    .fs-controls { width: min(760px, 100%); margin: 18px auto 0; grid-template-columns: auto minmax(130px, 220px); align-items: center; }
    .fs-actions, .fs-help { grid-column: 1 / -1; }
    .fs-topbar { flex-wrap: wrap; }
    .fs-new { margin-left: auto; }
}

@media (min-width: 901px) and (max-width: 1250px) {
    .fs-board { width: min(760px, calc(100vw - 24px)); }
    .fs-layout { display: block; }
    .fs-stage { margin: auto; }
    .fs-controls { width: min(760px, 100%); margin: 18px auto 0; grid-template-columns: auto 180px; }
    .fs-actions, .fs-help { grid-column: 1 / -1; }
}

@media (min-width: 700px) and (max-width: 900px) {
    .fs-page { padding-right: max(16px, env(safe-area-inset-right)); padding-left: max(16px, env(safe-area-inset-left)); }
}

@media (min-width: 700px) and (max-width: 1200px) and (orientation: landscape) {
    .fs-page { padding-top: 8px; padding-bottom: 28px; }
    .fs-topbar { gap: 10px; }
    .fs-status { min-height: 24px; margin: 8px 0; }
    .fs-stage { width: min(100%, 760px, calc(100vh - 200px)); }
    .fs-stage { width: min(100%, 760px, calc(100svh - 200px)); }
    .fs-stage { width: min(100%, 760px, calc(100dvh - 200px)); }
    .fs-controls { margin-top: 10px; }
}

@media (max-width: 500px) {
    .fs-topbar { gap: 8px; }
    .fs-topbar .fs-back { width: 100%; }
    .fs-title { font-size: 27px; }
    .fs-subtitle { font-size: 14px; }
    .fs-board { border-width: 3px; }
    .fs-board button { padding: 2px; }
    .fs-face-choice { min-height: 94px; padding: 5px; font-size: 13px; }
    .fs-face-grid { gap: 7px; }
    .fs-picker { width: 95vw; padding: 14px; }
    .fs-close { min-width: 90px; }
    .fs-face-choice .fs-token { width: clamp(60px, 10vw, 78px); height: clamp(60px, 10vw, 78px); }
    .fs-controls { grid-template-columns: 1fr 1fr; }
    .fs-actions .fs-button { padding-right: 4px; padding-left: 4px; }
}

@media (prefers-reduced-motion: reduce) {
    .fs-page *, .fs-page *::before, .fs-page *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
