/* ===== Reset & base ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #0a0a1a;
    --panel: #12122a;
    --panel-2: #1a1a38;
    --border: #2a2a5a;
    --text: #e6e6ff;
    --muted: #8a8ab5;
    --accent: #00d4ff;
    --hit: #2f9e5e;
    --near: #c39325;
    --miss: #33335c;
}

html, body { height: 100%; overscroll-behavior: none; }

body {
    position: fixed;
    inset: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Segoe UI', sans-serif;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

.game-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 100dvh;
    max-width: 520px;
    margin: 0 auto;
    padding:
        max(6px, env(safe-area-inset-top))
        max(10px, env(safe-area-inset-right))
        max(8px, env(safe-area-inset-bottom))
        max(10px, env(safe-area-inset-left));
}

/* ===== Toolbar ===== */
.toolbar { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; height: 42px; }
.toolbar-spacer { flex: 1; }

.game-name {
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    margin-left: 4px;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.icon-btn:active { transform: scale(0.93); border-color: var(--accent); }
.icon-btn-text { font-size: 0.76rem; font-weight: 700; }

/* ===== Status row ===== */
.status {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    margin: 6px 0 4px;
}

.mode-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 11px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--panel);
    color: var(--text);
    font-family: inherit;
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
}

.mode-chip:active { border-color: var(--accent); }
.mode-no { color: var(--accent); font-variant-numeric: tabular-nums; }

.status-tries {
    flex: 1;
    text-align: center;
    font-size: 0.76rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

/* ===== Board ===== */
.board-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.board { display: flex; flex-direction: column; gap: 6px; padding: 2px 0; }
.row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.row.is-invalid { animation: shake 0.4s; }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-7px); }
    40% { transform: translateX(7px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 5px 2px 4px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel);
    min-height: 46px;
}

.tile-char {
    font-size: clamp(1.15rem, 5.6vw, 1.5rem);
    font-weight: 700;
    line-height: 1.1;
    border-radius: 6px;
    padding: 0 5px;
}

.tile-pinyin {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: clamp(0.58rem, 2.7vw, 0.72rem);
    font-weight: 600;
    font-family: 'SF Mono', ui-monospace, Menlo, Consolas, monospace;
}

.pin {
    display: inline-block;
    min-width: 12px;
    padding: 1px 3px;
    border-radius: 4px;
    text-align: center;
    background: transparent;
    color: var(--muted);
}

.is-hit { background: var(--hit); color: #fff; }
.is-near { background: var(--near); color: #1a1400; }
.is-miss { background: var(--miss); color: #9a9ac4; }

.tile.is-empty { background: transparent; border-style: dashed; opacity: 0.5; }
.tile.is-empty .tile-char { color: transparent; }
.tile.is-current { border-color: var(--accent); }

/* ===== Composer ===== */
.composer { flex: 0 0 auto; padding-top: 6px; }

.suggestions {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 0 0 7px;
    scrollbar-width: none;
}

.suggestions::-webkit-scrollbar { display: none; }

.suggestion {
    flex: 0 0 auto;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel-2);
    color: var(--text);
    font-family: inherit;
    font-size: 0.92rem;
    white-space: nowrap;
    cursor: pointer;
}

.suggestion:active { border-color: var(--accent); }
.suggestion small { display: block; color: var(--muted); font-size: 0.62rem; letter-spacing: 0.04em; }

.input-row { display: flex; gap: 8px; }

.guess-input {
    flex: 1 1 auto;
    min-width: 0;
    height: 46px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--panel);
    color: var(--text);
    font-family: inherit;
    font-size: 1.02rem;
    letter-spacing: 0.06em;
}

.guess-input:focus { outline: none; border-color: var(--accent); }
.guess-input::placeholder { color: #5a5a80; letter-spacing: normal; font-size: 0.88rem; }

.btn {
    flex: 0 0 auto;
    min-height: 46px;
    padding: 0 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--panel);
    color: var(--text);
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.12s ease;
}

.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.45; }
.btn-primary { border-color: transparent; background: linear-gradient(135deg, var(--accent), #0080ff); color: #04121f; }
.btn-secondary { border-color: #7a4dd8; background: rgba(122, 77, 216, 0.16); color: #e0d0ff; }

.input-hint { margin-top: 5px; text-align: center; font-size: 0.68rem; color: var(--muted); }

/* ===== Toast ===== */
.toast {
    position: absolute;
    left: 50%;
    bottom: 96px;
    transform: translateX(-50%) translateY(6px);
    padding: 9px 18px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(10, 10, 26, 0.95);
    font-size: 0.84rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 30;
}

.toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Sheets ===== */
.sheet { position: absolute; inset: 0; z-index: 40; display: flex; align-items: flex-end; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(4, 4, 14, 0.72); }

.sheet-panel {
    position: relative;
    width: 100%;
    max-height: 88%;
    overflow-y: auto;
    padding: 16px 16px max(20px, env(safe-area-inset-bottom));
    border-radius: 20px 20px 0 0;
    border-top: 1px solid var(--border);
    background: linear-gradient(180deg, #1b1b3c, #101026);
    animation: sheetUp 0.24s ease;
}

@keyframes sheetUp { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { font-size: 1.05rem; font-weight: 800; letter-spacing: 0.06em; }
.sheet-panel p { color: var(--muted); font-size: 0.84rem; line-height: 1.7; margin-bottom: 8px; }
.legend-note { font-size: 0.74rem !important; }

.clue-group { margin-bottom: 12px; }
.clue-group h3 { font-size: 0.72rem; color: var(--muted); letter-spacing: 0.14em; margin-bottom: 6px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 5px; }

.chip {
    min-width: 30px;
    padding: 5px 7px;
    border-radius: 7px;
    background: var(--panel-2);
    color: var(--muted);
    text-align: center;
    font-family: 'SF Mono', ui-monospace, Menlo, monospace;
    font-size: 0.76rem;
    font-weight: 600;
}

.help-demo { margin: 4px 0 12px; }
.help-list { list-style: none; display: flex; flex-direction: column; gap: 7px; margin: 10px 0 14px; }
.help-list li { display: flex; align-items: center; gap: 9px; font-size: 0.82rem; color: var(--muted); }
.swatch { width: 17px; height: 17px; border-radius: 5px; flex: 0 0 auto; }

.stat-row { display: flex; gap: 8px; margin-bottom: 16px; }
.stat { flex: 1; text-align: center; padding: 10px 4px; border-radius: 12px; background: var(--panel-2); }
.stat b { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.64rem; color: var(--muted); }

.dist-title { font-size: 0.72rem; color: var(--muted); letter-spacing: 0.14em; margin-bottom: 8px; }
.dist { display: flex; flex-direction: column; gap: 4px; }
.dist-row { display: flex; align-items: center; gap: 7px; font-size: 0.74rem; font-variant-numeric: tabular-nums; }
.dist-row span:first-child { width: 16px; color: var(--muted); text-align: right; }
.dist-bar { height: 19px; min-width: 22px; padding: 0 6px; border-radius: 5px; background: var(--miss); display: flex; align-items: center; justify-content: flex-end; font-weight: 700; }
.dist-bar.is-current { background: var(--hit); }

.answer-card { text-align: center; padding: 14px 10px 6px; }
.answer-word { font-size: 1.9rem; font-weight: 800; letter-spacing: 0.16em; }
.answer-pinyin { margin-top: 5px; color: var(--accent); font-size: 0.86rem; letter-spacing: 0.06em; }
.answer-note { margin-top: 10px; font-size: 0.82rem !important; line-height: 1.75; }
.result-actions { display: flex; gap: 9px; margin-top: 12px; }
.result-actions .btn { flex: 1; }

@media (max-height: 660px) {
    .tile { min-height: 40px; padding: 3px 2px; }
    .board { gap: 4px; }
    .row { gap: 4px; }
    .input-hint { display: none; }
    .guess-input, .btn { min-height: 42px; height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
    .row.is-invalid, .sheet-panel { animation: none; }
}
