* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    color-scheme: dark;
    --bg: #0f0f1a;
    --panel: #172d2a;
    --panel-edge: #2c5b50;
    --text: #e7eceb;
    --muted: #a6b6b2;
    --accent: #4ecca3;
    --accent-dark: #183d35;
    --tile: #f4ead1;
    --tile-edge: #b8a77f;
    --tile-text: #17211f;
}

html.light {
    color-scheme: light;
    --bg: #edf4f1;
    --panel: #d8ebe4;
    --panel-edge: #8fb8a9;
    --text: #17211f;
    --muted: #4c625c;
    --accent: #16775d;
    --accent-dark: #c8e1d8;
}

body {
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.55;
}

main { max-width: 940px; margin: 0 auto; padding: 1rem; }

.breadcrumb { margin-bottom: 0.75rem; color: var(--muted); font-size: 0.85rem; }
.breadcrumb a, .content a { color: var(--accent); }
.breadcrumb a { text-decoration: none; }
.breadcrumb a:hover, .content a:hover { text-decoration: underline; }

.page-header { position: relative; display: flex; justify-content: center; align-items: center; min-height: 44px; }
h1 { margin-bottom: 1rem; color: var(--accent); font-size: 1.8rem; text-align: center; }

.theme-toggle-btn {
    position: absolute;
    top: 0;
    right: 0;
    width: 38px;
    height: 38px;
    border: 1px solid var(--panel-edge);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    cursor: pointer;
    font-size: 1.05rem;
}

.game-container {
    position: relative;
    margin-bottom: 2rem;
    padding: 0.75rem;
    overflow: hidden;
    border: 1px solid var(--panel-edge);
    border-radius: 14px;
    background: linear-gradient(145deg, #173e35, var(--panel));
}

html.light .game-container { background: linear-gradient(145deg, #e4f1ec, var(--panel)); }

.game-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.stats { display: flex; gap: 1rem; color: var(--muted); font-size: 0.88rem; }
.stats strong { display: block; color: var(--text); font-size: 1.05rem; text-align: center; }
.controls { display: flex; gap: 0.4rem; margin-left: auto; }

.controls button, .result-actions button {
    min-height: 40px;
    padding: 0.45rem 0.8rem;
    border: 1px solid var(--accent);
    border-radius: 7px;
    background: var(--accent-dark);
    color: var(--accent);
    cursor: pointer;
    font: inherit;
    font-weight: 700;
}

.controls button:hover:not(:disabled), .controls button:focus-visible,
.result-actions button:hover, .result-actions button:focus-visible { background: var(--accent); color: #0f1d19; }
.controls button:disabled { cursor: not-allowed; opacity: 0.42; }

.game-status { min-height: 1.6em; margin: 0.55rem 2.5rem 0.2rem 0; color: #d8eee7; font-size: 0.88rem; }
html.light .game-status { color: #294c42; }

.board-wrap { position: relative; display: flex; justify-content: center; }

.mahjong-board {
    position: relative;
    width: min(100%, 760px);
    aspect-ratio: 1.14 / 1;
    margin: 0 auto;
    border-radius: 10px;
    background:
        radial-gradient(circle at 50% 42%, rgba(255,255,255,0.08), transparent 48%),
        linear-gradient(145deg, #145345, #0b3028);
    box-shadow: inset 0 0 28px rgba(0,0,0,0.35);
    isolation: isolate;
}

.mahjong-tile {
    position: absolute;
    left: calc(var(--tile-x) * 8.13% + var(--tile-z) * -0.28% + 1.2%);
    top: calc(var(--tile-y) * 12.1% + var(--tile-z) * -0.45% + 1.5%);
    width: 8%;
    height: 11.8%;
    border: 1px solid var(--tile-edge);
    border-radius: clamp(3px, 0.7vw, 8px);
    background: linear-gradient(135deg, #fff8e8 0%, var(--tile) 72%, #d6c59e 100%);
    color: var(--tile-text);
    box-shadow:
        calc(1px + var(--tile-z) * 1px) calc(2px + var(--tile-z) * 1px) 0 #8b7954,
        0 3px 7px rgba(0,0,0,0.38);
    cursor: pointer;
    user-select: none;
    touch-action: manipulation;
    transition: filter 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

.mahjong-tile.blocked { cursor: not-allowed; filter: brightness(0.56) saturate(0.7); }
.mahjong-tile.free:hover, .mahjong-tile.free:focus-visible { transform: translateY(-2px); outline: 3px solid #71e5bd; outline-offset: 1px; }
.mahjong-tile.selected { outline: 4px solid #ffd45b; outline-offset: 1px; filter: brightness(1.08); }
.mahjong-tile.hinted { animation: hint-pulse 700ms ease-in-out infinite alternate; outline: 4px solid #58d7ff; outline-offset: 1px; }

.tile-glyph {
    display: grid;
    width: 100%;
    height: 100%;
    place-items: center;
    overflow: hidden;
    font-family: "Noto Sans Symbols 2", "Segoe UI Symbol", sans-serif;
    font-size: clamp(1rem, 4.2vw, 2.7rem);
    line-height: 1;
}

@keyframes hint-pulse {
    from { filter: brightness(1); }
    to { filter: brightness(1.25); }
}

.result-overlay {
    position: absolute;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    padding: 1rem;
    border-radius: 10px;
    background: rgba(8, 18, 16, 0.88);
    color: #eefaf6;
    text-align: center;
}

.result-overlay.hidden { display: none; }
.result-overlay h2 { color: #72e2bd; font-size: 2rem; }
.result-overlay p { max-width: 34rem; }
.result-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; justify-content: center; }
.result-actions button { background: #183d35; }
.result-actions .share-btn { border-color: #65b9d1; color: #a9e9fb; }

.fullscreen-btn {
    position: absolute;
    top: 0.65rem;
    right: 0.65rem;
    z-index: 300;
    width: 34px;
    height: 34px;
    border: 1px solid var(--panel-edge);
    border-radius: 7px;
    background: rgba(10, 31, 26, 0.9);
    color: #d7f5eb;
    cursor: pointer;
    font-size: 1.05rem;
}

.content { padding-top: 1.2rem; border-top: 1px solid var(--panel-edge); }
.last-updated { margin-bottom: 0.8rem; color: var(--muted); font-size: 0.8rem; }
.content h2 { margin: 1.5rem 0 0.7rem; color: var(--accent); font-size: 1.28rem; }
.content p { margin-bottom: 0.8rem; color: var(--muted); }
.content ul { margin: 0.5rem 0 1rem 1.5rem; color: var(--muted); }
.content li { margin-bottom: 0.5rem; }
.faq { margin-bottom: 1.5rem; }
.faq dt { margin-top: 0.9rem; color: var(--text); font-weight: 700; }
.faq dd { margin-top: 0.2rem; color: var(--muted); }

.related-games { margin-top: 1.5rem; }
.related-games h3 { margin-bottom: 0.7rem; color: var(--accent); font-size: 1rem; }
.game-links { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.game-links a {
    display: inline-block;
    padding: 0.45rem 0.85rem;
    border: 1px solid var(--panel-edge);
    border-radius: 6px;
    background: var(--panel);
    color: var(--accent);
    text-decoration: none;
    font-size: 0.9rem;
}
.game-links a:hover, .game-links a:focus-visible { border-color: var(--accent); text-decoration: none; }

@media (min-width: 680px) {
    main { padding: 2rem; }
    h1 { font-size: 2.1rem; }
    .game-container { padding: 1rem; }
}

@media (max-width: 560px) {
    .game-toolbar { align-items: stretch; }
    .stats { width: 100%; justify-content: space-around; padding-right: 2rem; }
    .controls { width: 100%; margin-left: 0; }
    .controls button { flex: 1; padding-inline: 0.35rem; font-size: 0.88rem; }
    .game-status { margin-right: 0; font-size: 0.78rem; }
    .game-container { padding: 0.5rem; }
    .mahjong-board { width: 100%; }
    .mahjong-tile { border-width: 1px; box-shadow: 1px 2px 0 #8b7954, 0 2px 4px rgba(0,0,0,0.4); }
    .tile-glyph { font-size: clamp(0.9rem, 5.4vw, 1.55rem); }
    .fullscreen-btn { top: 0.5rem; right: 0.5rem; width: 30px; height: 30px; }
}

@media (orientation: landscape) and (max-height: 560px) {
    main { padding-top: 0.5rem; }
    .mahjong-board { width: min(88vh, 760px); }
}

@media (prefers-reduced-motion: reduce) {
    .mahjong-tile { transition: none; }
    .mahjong-tile.hinted { animation: none; }
}
