:root {
    --bg: #0b1016;
    --panel: #141b24;
    --panel-soft: #192330;
    --line: #2d3948;
    --text: #f4f7fb;
    --muted: #bac5d4;
    --accent: #d8c08c;
    --accent-strong: #f1d996;
    --danger: #f07575;
    --shadow: 0 22px 70px rgba(0, 0, 0, 0.34);
}

* {
    box-sizing: border-box;
}

html {
    color-scheme: dark;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    font-family: "Segoe UI", "Yu Gothic", "Hiragino Sans", "Meiryo", sans-serif;
    background:
        linear-gradient(145deg, rgba(23, 33, 45, 0.7), rgba(11, 16, 22, 0.96)),
        #0b1016;
}

button,
input {
    font: inherit;
}

button {
    min-height: 42px;
    border: 1px solid rgba(216, 192, 140, 0.36);
    border-radius: 8px;
    background: rgba(216, 192, 140, 0.12);
    color: var(--text);
    cursor: pointer;
}

button:hover,
button:focus-visible {
    border-color: var(--accent-strong);
    outline: none;
}

a {
    color: inherit;
    text-decoration: none;
}

.game-shell {
    width: min(1120px, calc(100% - 28px));
    margin: 0 auto;
    padding: 24px 0 42px;
}

.game-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.back-link {
    order: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 72px;
    min-height: 38px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: clamp(2.1rem, 5vw, 3.4rem);
    line-height: 1;
}

h2 {
    margin-bottom: 12px;
    font-size: 1rem;
}

.play-layout {
    display: grid;
    grid-template-columns: minmax(300px, 520px) minmax(280px, 360px);
    gap: 18px;
    align-items: start;
}

.board-wrap {
    position: relative;
    display: grid;
    place-items: center;
    padding: clamp(10px, 2vw, 18px);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #0f151d;
    box-shadow: var(--shadow);
}

#gameCanvas {
    display: block;
    width: min(100%, 420px);
    aspect-ratio: 1 / 2;
    height: auto;
    border: 1px solid #3a4654;
    border-radius: 4px;
    background: #080d12;
}

.status-overlay {
    position: absolute;
    inset: 18px;
    display: grid;
    place-content: center;
    gap: 8px;
    border-radius: 8px;
    background: rgba(8, 12, 17, 0.72);
    text-align: center;
}

.status-overlay[hidden] {
    display: none;
}

.status-overlay strong {
    font-size: 1.7rem;
}

.status-overlay span {
    color: var(--muted);
}

.side-panel {
    display: grid;
    gap: 12px;
}

.panel-block {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.next-block {
    display: grid;
    justify-items: center;
}

#nextCanvas {
    width: 128px;
    height: 128px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #0b1118;
}

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

.stats-grid div {
    min-width: 0;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 8px;
    background: var(--panel-soft);
}

.stats-grid span {
    display: block;
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 0.78rem;
}

.stats-grid strong {
    display: block;
    font-size: clamp(1.1rem, 4vw, 1.6rem);
    line-height: 1.1;
}

.actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.controls dl {
    display: grid;
    gap: 7px;
    margin: 0;
}

.controls div,
.ranking-list li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.controls dt {
    color: var(--accent-strong);
    font-weight: 700;
}

.controls dd {
    margin: 0;
    color: var(--muted);
}

.ranking-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.ranking-head span {
    color: var(--muted);
    font-size: 0.82rem;
}

.ranking-list {
    display: grid;
    gap: 8px;
    margin: 0;
    padding-left: 1.35rem;
}

.ranking-list li {
    padding: 8px 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.ranking-list .empty {
    display: list-item;
    color: var(--muted);
}

.score-form {
    display: grid;
    gap: 8px;
    margin-top: 14px;
}

.score-form label {
    color: var(--muted);
    font-size: 0.85rem;
}

.submit-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

.submit-row input {
    min-width: 0;
    min-height: 42px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #0d131b;
    color: var(--text);
}

.submit-status {
    min-height: 1.4em;
    margin: 0;
    color: var(--muted);
    font-size: 0.85rem;
}

.submit-status.is-error {
    color: var(--danger);
}

@media (max-width: 860px) {
    .play-layout {
        grid-template-columns: 1fr;
    }

    .side-panel {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .ranking,
    .controls {
        grid-column: 1 / -1;
    }
}

@media (max-width: 560px) {
    .game-shell {
        width: min(100% - 18px, 1120px);
        padding-top: 16px;
    }

    .game-header {
        align-items: start;
    }

    .side-panel,
    .stats-grid,
    .actions {
        grid-template-columns: 1fr;
    }
}
