/* Flat application shell. Puzzle geometry remains owned by grid.css. */

:root {
    --color-primary: #6f7ece;
    --color-primary-bright: #5262b5;
    --color-on-primary: #ffffff;
    --color-secondary: #2c3e50;
    --color-accent: #ff7300;
    --color-background: #f5f7fa;
    --color-foreground: #17212b;
    --color-muted: #e0e5ea;
    --color-border: #b0b7c3;
    --surface-1: #ffffff;
    --surface-2: #f5f7fa;
    --surface-3: #e8ecf1;
    --global-bg: #f5f7fa;
    --global-bg-deep: #f5f7fa;
    --primary-text: #000000;
    --secondary-text: #2c3e50;
    --divider-color: #b0b7c3;
    --button-focus-ring: #1b2836;
    --shadow-sm: none;
    --shadow-md: none;
    --shadow-lg: none;
    --shadow-xl: none;
    --radius-sm: 0;
    --radius-md: 0;
    --radius-lg: 0;
    --radius-xl: 0;

    --hint-text-normal: #ff9595;
    --hint-text-highlight: #000000;
    --hint-bg-normal: #ffffff;
    --hint-bg-highlight: #6f7dce3f;
    --hint-bg-checker-even: #ffffff;
    --hint-bg-checker-odd: rgba(225, 244, 254, 0.55);
    --cell-fill: #6f7ece;
    --cell-cross: #ff7300;
    --cell-border-thin: #8d9ca0;
    --cell-border-thick: #ffa600;
    --cell-border-outer: #747474;
    --cell-hover: #ff7b00;
    --cell-place-trail: #6f7ece;
    --cell-bg-checker-even: rgba(225, 244, 254, 0.55);
    --cell-bg-checker-odd: #ffffff;
    --hud-bg: #f5f7fa;
    --hud-text: #2c3e50;
    --hud-button-bg: #2c3e50;
    --hud-button-text: #f5f7fa;
    --menu-bg: #ffffff;
    --menu-text: #2c3e50;
    --menu-button-bg: #2c3e50;
    --menu-button-hover-bg: #e0e5ea;
    --menu-overlay: rgba(44, 62, 80, 0.5);
    --navigator-on: #2c3e50;
    --navigator-off: #f5f7fa;
    --navigator-focus: #1b2836;
    --history-block-bg: #ffffff;
    --history-started: #e0e5ea;
    --history-partial: #cdd4db;
    --history-solved: #2c3e50;
    --history-unstarted: #ffffff;
    --button-bg: #2c3e50;
    --button-text: #f5f7fa;
    --button-hover-bg: #e0e5ea;
    --button-hover-text: #2c3e50;
    --button-active-bg: #1b2836;
    --button-disabled-bg: #cccccc;
}

html { color-scheme: light; }

body {
    color: var(--primary-text);
    background: var(--global-bg);
}

body::before { display: none; }

body * { border-radius: 0 !important; }

#app {
    width: 100%;
    min-width: 0;
    max-width: 100%;
}

.editor-banner { background: #f5f7fa !important; }

button,
.control-button,
select,
input[type="text"],
input[type="number"] {
    border-radius: 0 !important;
    box-shadow: none !important;
}

button:not(:disabled):hover,
.control-button:not(:disabled):hover {
    border-color: var(--secondary-text);
    box-shadow: none !important;
    transform: none;
}

.skip-link {
    position: fixed;
    top: 0;
    left: 50%;
    z-index: 2000;
    min-height: 44px;
    padding: 10px 16px;
    color: #ffffff;
    background: #2c3e50;
    border: 1px solid #1b2836;
    border-radius: 0;
    font-weight: 700;
    text-decoration: none;
    transform: translate(-50%, -110%);
}

.skip-link:focus { transform: translate(-50%, 0); }

.app-shell {
    width: min(100%, 1680px);
    min-width: 0;
    max-width: 100%;
    gap: 20px;
}

.app-header {
    position: relative;
    z-index: 100;
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    width: 100%;
    min-height: 58px;
    border: 1px solid var(--divider-color);
    background: #ffffff;
}

.brand-lockup {
    display: inline-flex;
    align-items: center;
    min-width: 132px;
    padding: 0 18px;
    color: #1b2836;
    border-right: 1px solid var(--divider-color);
    text-decoration: none;
}

.brand-wordmark {
    font-size: 1.08rem;
    font-weight: 900;
    letter-spacing: 0.22em;
    line-height: 1;
}

.header-actions { display: flex; align-items: stretch; }

.header-seed { display: flex; align-items: center; min-width: 0; flex: 1 1 auto; padding: 8px 18px; gap: 9px; color: #536272; font-size: 0.7rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.header-seed input { width: min(220px, 100%); min-width: 80px; height: 38px; padding: 0 10px; border: 1px solid var(--divider-color); background: #f5f7fa; }

.app-header .icon-label-button {
    position: static !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto !important;
    height: auto !important;
    min-height: 56px !important;
    padding: 0 16px !important;
    gap: 8px;
    color: #2c3e50 !important;
    border: 0 !important;
    border-left: 1px solid var(--divider-color) !important;
    background: #ffffff !important;
}

.app-header .icon-label-button:hover { background: #e8ecf1 !important; }

.icon-label-button svg,
.primary-action svg,
.close-button svg,
#history-pagination svg {
    width: 19px;
    height: 19px;
    flex: 0 0 auto;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: square;
    stroke-linejoin: miter;
}

.game-workspace {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
    align-items: start;
    width: 100%;
    gap: 20px;
}

.game-hud {
    position: sticky !important;
    top: 20px;
    display: flex !important;
    flex-direction: column;
    align-items: stretch !important;
    width: 100% !important;
    min-width: 0;
    max-width: none !important;
    gap: 16px !important;
    padding: 18px;
    overflow: hidden;
    border: 1px solid var(--divider-color);
    background: #ffffff;
}

.puzzle-identity { text-align: left; }

.eyebrow,
.section-kicker {
    display: block;
    margin-bottom: 5px;
    color: #5262b5;
    font-size: 0.67rem;
    font-weight: 800;
    letter-spacing: 0.11em;
    line-height: 1.3;
    text-transform: uppercase;
}

.puzzle-title-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    gap: 8px;
}

.puzzle-title-row h1,
.stage-heading h2,
.sheet-header h2,
.account-content h3 {
    margin: 0;
    color: #17212b;
    font-weight: 750;
    letter-spacing: -0.025em;
    line-height: 1.15;
}

.puzzle-title-row h1 {
    display: block;
    width: 100%;
    min-width: 0;
    overflow: hidden;
    font-size: 1.35rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.size-badge {
    flex: 0 0 auto;
    padding: 2px 5px;
    color: #2c3e50;
    border: 1px solid var(--divider-color);
    border-radius: 0;
    background: #f5f7fa;
    font-size: 0.72rem;
    font-weight: 700;
}

.generation-status { min-height: 18px; margin-top: 7px; color: #536272; font-size: 0.75rem; text-align: left; }

.game-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.game-actions .control-button { width: 100%; min-height: 44px; }
.new-puzzle-panel, .creator-panel { display: grid; width: 100%; min-width: 0; max-width: 100%; gap: 10px; padding: 12px; border: 1px solid var(--divider-color); background: #f5f7fa; }
.new-puzzle-panel h2, .creator-panel h2 { margin: 0; color: #17212b; font-size: 0.9rem; }
.puzzle-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; min-width: 0; gap: 8px; }
.puzzle-options select { width: 100%; min-width: 0; min-height: 40px; padding: 0 8px; border: 1px solid var(--divider-color); background: #ffffff; }
.new-puzzle-panel .primary-action { width: 100%; }
.creator-panel { background: #ffffff; }
.creator-panel p { margin: 3px 0 0; color: #536272; font-size: 0.7rem; line-height: 1.35; }

.status-rail {
    display: grid !important;
    grid-template-columns: 1fr;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    gap: 8px !important;
    border: 0 !important;
    background: none !important;
}

.metric-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    min-width: 0;
    min-height: 64px;
    padding: 10px 11px;
    gap: 1px;
    border: 1px solid var(--divider-color);
    border-radius: 0;
    background: #f5f7fa;
    text-align: left;
}

.metric-card strong { color: #17212b; font-size: 0.83rem; font-variant-numeric: tabular-nums; }

#timer-display.metric-card {
    flex: initial;
    align-items: flex-start;
    min-height: 78px;
    padding: 10px 11px;
    text-align: left;
}

#puzzle-name-display,
#mistake-display { min-height: 0; padding: 0; border: 0; background: none; text-align: left; }

#puzzle-name-display { display: block; width: 100%; flex: none; }

#grid-size-display.size-badge { display: inline-flex; min-height: 0; }
.metric-label { color: #536272; font-size: 0.64rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.metric-detail { color: #536272; font-size: 0.65rem; }
.metric-penalty { color: #b44b00; }

.navigator-card {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    min-height: 58px;
    gap: 10px;
    cursor: pointer;
}

.navigator-card input {
    position: static;
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    margin: 0;
    accent-color: #2c3e50;
    opacity: 1;
    pointer-events: auto;
}

.navigator-card span { display: grid; gap: 1px; }
.navigator-card small { color: #536272; font-size: 0.67rem; font-weight: 500; line-height: 1.3; }

#navigator-label {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    min-height: 44px;
    gap: 9px;
    color: #2c3e50;
    background: #ffffff;
}

#navigator-label input {
    position: static;
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: #2c3e50;
    opacity: 1;
}

.primary-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 46px !important;
    gap: 8px;
    color: #ffffff !important;
    border-color: #1b2836 !important;
    background: #2c3e50 !important;
}

.primary-action:hover { color: #2c3e50 !important; background: #e0e5ea !important; }

.game-stage {
    display: flex !important;
    flex-direction: column;
    align-items: stretch !important;
    width: 100% !important;
    min-width: 0;
    gap: 12px;
}

.control-hint {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px 18px;
    color: #536272;
    font-size: 0.72rem;
    line-height: 1.35;
}

.control-hint > span { display: inline-flex; align-items: center; gap: 6px; }
.control-hint strong { color: #2c3e50; font-weight: 700; }

.control-cell {
    position: relative;
    display: inline-block;
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    border: 1px solid var(--cell-border-thin);
    background: var(--cell-bg-checker-odd);
}

.control-cell-fill {
    background: var(--cell-fill);
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.55) !important;
}

.control-cell-cross::before,
.control-cell-cross::after {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 70%;
    height: 4px;
    background: var(--cell-cross);
    content: "";
}

.control-cell-cross::before { transform: translate(-50%, -50%) rotate(45deg); }
.control-cell-cross::after { transform: translate(-50%, -50%) rotate(-45deg); }

.control-cell-dot::before {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 5px;
    height: 5px;
    background: var(--cell-cross);
    content: "";
    transform: translate(-50%, -50%);
}

.board-frame {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: clamp(520px, calc(100dvh - 190px), 840px);
    overflow: hidden;
    border: 1px solid var(--divider-color);
    border-radius: 0;
    background: #ffffff;
}

.board-frame::before { display: none; }
.board-frame #grid-wrapper { position: relative; z-index: 1; }
.board-help { max-width: 64ch; margin: 0 auto; color: #536272; font-size: 0.76rem; }

.site-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    width: 100%;
    padding: 13px 0 0;
    gap: 16px;
    border-top: 1px solid var(--divider-color);
    color: #536272;
    font-size: 0.74rem;
}

.site-footer a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 14px;
    color: var(--button-text);
    border: 1px solid var(--button-bg);
    background: var(--button-bg);
    font-weight: 700;
    text-decoration: none;
}

.site-footer a:hover { color: var(--button-hover-text); background: var(--button-hover-bg); }

.sheet-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: rgba(44, 62, 80, 0.5);
    opacity: 0;
    pointer-events: none;
}

.sheet-overlay.visible { opacity: 1; pointer-events: auto; }

.app-sheet {
    color: var(--menu-text);
    border: 1px solid #747d87;
    border-radius: 0 !important;
    background: #ffffff;
    box-shadow: 6px 6px 0 rgba(27, 40, 54, 0.18);
    backdrop-filter: none;
}

#settings-menu { display: block; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; width: 100%; margin-bottom: 20px; gap: 20px; text-align: left; }
.sheet-header h2 { font-size: clamp(1.4rem, 3vw, 2rem); }
.close-button { display: inline-grid; place-items: center; flex: 0 0 44px; width: 44px !important; height: 44px; padding: 0 !important; border-radius: 0 !important; }
.sheet-content { width: 100%; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 12px; }

.menu-section {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    min-width: 0;
    padding: 15px;
    border: 1px solid var(--divider-color);
    border-radius: 0;
    background: #f5f7fa;
    text-align: left;
}

.menu-section h3 { margin: 0; color: #17212b; font-size: 1rem; }
.solver-status-stack { display: grid; gap: 7px; }
.button-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.field-grid { display: grid; gap: 11px; }
.field-label { display: grid; gap: 5px; color: #536272; font-size: 0.76rem; font-weight: 700; }
.field-label select, .field-label input { width: 100%; min-width: 0; }
.options-actions { margin-top: 3px; }

.account-sheet {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 1200;
    width: min(520px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
    padding: 28px;
    overflow: auto;
    border-radius: 0;
    opacity: 0;
    transform: translate(-50%, calc(-50% + 12px));
    pointer-events: none;
}

.account-sheet.open { opacity: 1; transform: translate(-50%, -50%); pointer-events: auto; }
.account-content { text-align: center; }
.passkey-visual { display: grid; place-items: center; width: 72px; height: 72px; margin: 0 auto 18px; color: #ffffff; border: 1px solid #1b2836; border-radius: 0; background: #6f7ece; }
.passkey-visual svg { width: 38px; height: 38px; stroke: currentColor; stroke-width: 2.2; stroke-linecap: square; stroke-linejoin: miter; }
.account-content h3 { font-size: clamp(1.25rem, 4vw, 1.65rem); }
.account-content > p { max-width: 42ch; margin: 12px auto; color: #536272; }
#account-status:not(:empty) { margin: 14px 0; padding: 10px; color: #17212b; border: 1px solid var(--divider-color); border-radius: 0; background: #f5f7fa; }
.account-actions { display: grid; gap: 8px; margin-top: 20px; }
.account-actions .control-button { width: 100%; min-height: 46px; }
.account-privacy { font-size: 0.72rem; }

@media (max-width: 1024px) {
    .game-workspace { grid-template-columns: 1fr; }
    .game-hud { position: relative !important; top: auto; }
    .status-rail { grid-template-columns: 1.4fr 1fr 1.4fr 1fr; }
    .metric-card, #timer-display.metric-card { min-height: 70px; }
    .board-frame { min-height: clamp(420px, calc(100dvh - 240px), 720px); }
}

@media (max-width: 720px) {
    .app-header { align-items: stretch; }
    .brand-lockup { min-width: 104px; padding: 0 12px; }
    .brand-wordmark { font-size: 0.94rem; }
    .header-seed { padding: 7px 9px; }
    .header-seed span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
    .app-header .icon-label-button { width: 48px !important; padding: 0 !important; }
    .icon-label-button span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
    .status-rail { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .control-hint { justify-content: flex-start; }
    .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    #content-wrapper {
        width: 100%;
        min-height: 100svh;
        padding-right: max(10px, env(safe-area-inset-right));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
        padding-left: max(10px, env(safe-area-inset-left));
    }
    .app-shell { gap: 14px; }
    .app-header { min-width: 0; min-height: 54px; max-width: 100%; }
    .brand-lockup { min-width: 96px; padding: 0 10px; }
    .brand-wordmark { font-size: 0.86rem; letter-spacing: 0.16em; }
    .app-header { flex-wrap: wrap; }
    .header-seed { order: 3; flex-basis: 100%; border-top: 1px solid var(--divider-color); }
    .header-actions { min-width: 0; flex: 0 0 auto; }
    .app-header .icon-label-button { min-height: 52px !important; width: 44px !important; }
    .game-hud { padding: 13px; }
    .puzzle-title-row h1 { font-size: 1.2rem; }
    .metric-card { min-height: 62px; padding: 9px; }
    .board-frame { min-height: 0; }
    .site-footer { max-width: 100%; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
    .account-sheet { width: calc(100vw - 20px); max-height: calc(100dvh - 20px); padding: 20px 16px; }
    .button-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    .account-sheet,
    .sheet-overlay,
    .skip-link { transition-duration: 0.01ms !important; }
}
