:root {
  color-scheme: dark;
  --ink: #f6f0df;
  --muted: #b9c8bf;
  --gold: #e7bb5f;
  --red: #dd5d4f;
  --green: #0f6b4f;
  --deep: #071812;
  --panel: rgba(4, 20, 15, .82);
  --line: rgba(230, 208, 151, .2);
}

* { box-sizing: border-box; }
html { overflow-x: hidden; background: var(--deep); }
body {
  margin: 0;
  min-height: 100svh;
  overflow-x: hidden;
  color: var(--ink);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  background:
    radial-gradient(circle at 50% 0%, rgba(36, 115, 83, .4), transparent 40%),
    linear-gradient(135deg, #030b08 0%, #09251b 48%, #020806 100%);
}
button { font: inherit; }
button:focus-visible, .tile:focus-visible { outline: 3px solid #ffe09a; outline-offset: 3px; }
.app-shell { width: min(1320px, 100%); margin: 0 auto; padding: 0 18px 36px; }
.topbar { min-height: 84px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark, .moon-logo { display: grid; place-items: center; border-radius: 50%; color: #183629; background: var(--gold); font-family: serif; font-weight: 900; box-shadow: 0 0 30px rgba(231,187,95,.23); }
.brand-mark { width: 44px; height: 44px; }
.brand h1 { font-size: clamp(19px, 3vw, 27px); letter-spacing: .08em; margin: 0; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 11px; letter-spacing: .12em; }
.header-actions { display: flex; gap: 8px; }
.icon-btn { border: 1px solid var(--line); background: rgba(255,255,255,.04); color: var(--ink); padding: 10px 13px; border-radius: 999px; cursor: pointer; }
.icon-btn:hover { background: rgba(255,255,255,.1); }
.status-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); width: min(660px, 100%); margin: 0 auto 12px; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: rgba(0,0,0,.2); }
.status-strip div { padding: 8px 12px; text-align: center; border-right: 1px solid var(--line); }
.status-strip div:last-child { border: 0; }
.status-strip small { display: block; color: var(--muted); font-size: 10px; }
.status-strip strong { font-size: 14px; }

.mahjong-table {
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 760px;
  overflow: hidden;
  border: 1px solid rgba(231,187,95,.24);
  border-radius: 38px;
  background:
    linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px),
    radial-gradient(circle, #176f53 0%, #0c543d 52%, #063425 100%);
  background-size: 32px 32px, 32px 32px, auto;
  box-shadow: inset 0 0 80px rgba(0,0,0,.5), 0 24px 70px rgba(0,0,0,.3);
}
.mahjong-table::after { content: ""; position: absolute; inset: 18px; border: 1px solid rgba(255,255,255,.08); border-radius: 25px; pointer-events: none; }
.player-zone { position: absolute; z-index: 2; }
.top-player { top: 22px; left: 50%; width: 560px; transform: translateX(-50%); }
.left-player { left: 20px; top: 50%; width: 300px; transform: translateY(-50%); }
.right-player { right: 20px; top: 50%; width: 300px; transform: translateY(-50%); }
.bottom-player { left: 26px; right: 26px; bottom: 22px; }
.opponent .identity { justify-content: center; margin-bottom: 7px; }
.identity { display: flex; align-items: center; gap: 8px; min-height: 28px; }
.identity b { letter-spacing: .08em; }
.identity strong { color: #fff1bd; font-variant-numeric: tabular-nums; }
.wind-badge { display: inline-grid; place-items: center; width: 27px; height: 27px; border-radius: 8px; color: #163227; background: var(--gold); font-family: serif; font-weight: 900; }
.riichi-badge { padding: 3px 7px; border-radius: 999px; color: #fff; background: var(--red); font-size: 10px; font-weight: 900; }
.tile-backs { display: flex; justify-content: center; gap: 2px; }
.tile-back { width: 27px; height: 39px; border: 2px solid #dbceb6; border-radius: 4px; background: repeating-linear-gradient(45deg,#255f51 0 4px,#193f36 4px 8px); box-shadow: 0 2px 2px rgba(0,0,0,.3); }
.left-player .tile-backs, .right-player .tile-backs { max-width: 180px; margin: auto; flex-wrap: wrap; }
.discard-river { display: grid; grid-template-columns: repeat(6, 28px); justify-content: center; align-content: start; gap: 3px; min-height: 86px; margin-top: 9px; }
.river-tile, .mini-tile { display: grid; place-items: center; width: 28px; height: 38px; color: #191b18; background: #f6f0df; border: 1px solid #d5cab3; border-radius: 4px; font-family: "Apple Symbols", "Noto Sans Symbols 2", serif; font-size: 22px; box-shadow: 0 2px 3px rgba(0,0,0,.25); }
.river-tile.called { opacity: .35; }
.mini-tile { width: 34px; height: 45px; font-size: 27px; }
.melds { display: flex; gap: 6px; min-height: 32px; }
.meld { display: flex; gap: 1px; padding: 2px; border-radius: 5px; background: rgba(0,0,0,.2); }
.meld .river-tile { width: 24px; height: 32px; font-size: 18px; }
.human-meta { display: flex; justify-content: space-between; align-items: end; padding: 0 7px 8px; }
.human-hand { display: flex; justify-content: center; align-items: end; gap: 3px; width: 100%; max-width: 100%; min-width: 0; min-height: 84px; padding: 8px 10px; overflow-x: auto; scrollbar-width: thin; }
.tile { flex: 0 0 auto; width: clamp(41px, 5.5vw, 61px); height: clamp(59px, 7.8vw, 84px); border: 0; border-bottom: 5px solid #c2b69e; border-radius: 7px; color: #171a16; background: linear-gradient(150deg,#fffef6,#e7dfcd); font-family: "Apple Symbols", "Noto Sans Symbols 2", serif; font-size: clamp(31px, 4.7vw, 47px); box-shadow: 0 5px 8px rgba(0,0,0,.33); cursor: pointer; transition: transform .13s ease, box-shadow .13s ease, filter .13s ease; }
.tile:hover { transform: translateY(-5px); }
.tile.selected { transform: translateY(-12px); box-shadow: 0 0 0 4px #f2c56a, 0 10px 14px rgba(0,0,0,.34); }
.tile.drawn { margin-left: 9px; }
.tile.locked { filter: grayscale(.45) brightness(.72); cursor: not-allowed; }
.tile.valid-riichi { box-shadow: 0 0 0 3px #ef7d70, 0 5px 8px rgba(0,0,0,.33); }
.center-board { position: absolute; z-index: 1; left: 50%; top: 49%; width: 190px; height: 190px; transform: translate(-50%,-50%) rotate(45deg); display: grid; grid-template-columns: 1fr 1fr; border: 2px solid rgba(230,208,151,.42); border-radius: 24px; overflow: hidden; color: var(--ink); background: rgba(2,20,14,.8); box-shadow: 0 12px 40px rgba(0,0,0,.35); }
.center-board > div { transform: rotate(-45deg); display: grid; place-items: center; text-align: center; }
.round-wind { font: 900 43px serif; color: var(--gold); }
.center-info small { display: block; color: var(--muted); font-size: 8px; letter-spacing: .12em; }
.turn-light { font-size: 10px; line-height: 1.2; }
.turn-light i { display: block; width: 12px; height: 12px; margin-bottom: 4px; border-radius: 50%; background: #79dbac; box-shadow: 0 0 15px #79dbac; }
.sticks { color: var(--muted); font-size: 11px; }
.message-bar { position: absolute; z-index: 3; left: 50%; bottom: 134px; width: min(520px, 70%); transform: translateX(-50%); padding: 9px 14px; text-align: center; border: 1px solid rgba(255,255,255,.13); border-radius: 999px; background: rgba(1,12,9,.83); backdrop-filter: blur(8px); color: #fff4ce; font-weight: 700; font-size: 13px; }

.command-panel { display: flex; justify-content: center; align-items: center; gap: 12px; width: 100%; min-width: 0; min-height: 82px; margin-top: 12px; padding: 11px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); }
.action-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; }
.action-btn { min-width: 75px; min-height: 48px; border: 1px solid #d5b76c; border-radius: 12px; color: #ffe8ae; background: rgba(132,85,21,.34); font-weight: 900; cursor: pointer; }
.action-btn:hover { background: rgba(190,127,38,.46); }
.action-btn.pass { border-color: rgba(255,255,255,.18); color: var(--muted); background: rgba(255,255,255,.05); }
.discard-btn, .primary-btn { border: 0; border-radius: 12px; color: #132a21; background: linear-gradient(135deg,#f7d98f,#dca94a); font-weight: 900; cursor: pointer; box-shadow: 0 7px 18px rgba(0,0,0,.24); }
.discard-btn { min-width: 190px; min-height: 50px; padding: 0 20px; }
.discard-btn:disabled { color: #7f8a84; background: #33463e; box-shadow: none; cursor: not-allowed; }
.sub-panels { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.guide-card, .log-card { min-height: 165px; padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); }
.eyebrow { color: var(--gold); font-size: 10px; font-weight: 900; letter-spacing: .16em; }
.guide-card h2, .log-card h2 { margin: 5px 0 8px; font-size: 18px; }
.guide-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.guide-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.guide-tags span { padding: 6px 9px; border-radius: 7px; color: #183026; background: #e9e0ca; font-family: serif; font-size: 13px; }
.log-card ol { margin: 0; padding-left: 20px; color: var(--muted); font-size: 12px; line-height: 1.75; }

.modal { position: fixed; z-index: 20; inset: 0; display: none; place-items: center; padding: 18px; background: rgba(0,8,5,.78); backdrop-filter: blur(10px); }
.modal.open { display: grid; animation: fadeIn .2s ease; }
.modal-card { position: relative; width: min(560px, 100%); max-height: calc(100svh - 36px); overflow-y: auto; padding: 34px; text-align: center; border: 1px solid rgba(231,187,95,.34); border-radius: 24px; background: linear-gradient(155deg,#12382b,#06140f); box-shadow: 0 30px 90px #000; }
.modal-card h2 { margin: 7px 0 8px; font-family: serif; font-size: clamp(31px, 7vw, 52px); letter-spacing: .08em; }
.modal-card > p { color: var(--muted); line-height: 1.7; }
.moon-logo { width: 72px; height: 72px; margin: 0 auto 18px; font-size: 34px; }
.mode-note { display: grid; gap: 4px; margin: 22px 0; padding: 13px; border-radius: 12px; background: rgba(255,255,255,.055); }
.mode-note b { color: #ffe4a3; }
.mode-note span { color: var(--muted); font-size: 12px; }
.primary-btn { width: min(330px, 100%); min-height: 55px; padding: 0 22px; font-size: 17px; }
.text-btn { margin-top: 12px; border: 0; color: var(--muted); background: transparent; text-decoration: underline; cursor: pointer; }
.close-btn { position: absolute; top: 12px; right: 15px; width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; color: var(--ink); background: rgba(255,255,255,.05); font-size: 24px; cursor: pointer; }
.steps { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 22px 0; text-align: left; }
.steps > div { display: flex; gap: 10px; padding: 12px; border-radius: 12px; background: rgba(255,255,255,.05); }
.steps b { flex: 0 0 auto; display: grid; place-items: center; width: 27px; height: 27px; border-radius: 50%; color: #173228; background: var(--gold); }
.steps p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.steps strong { color: var(--ink); }
.fine-print { font-size: 11px; }
.result-hand { display: flex; justify-content: center; flex-wrap: wrap; gap: 2px; margin: 18px 0; }
.result-hand .river-tile { width: 34px; height: 47px; font-size: 27px; }
.yaku-list { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; }
.yaku-list span { padding: 5px 9px; border-radius: 999px; color: #163227; background: #e4d4aa; font-size: 12px; font-weight: 900; }
.point-result { margin: 14px 0 4px; color: #ffd87f; font-size: clamp(30px, 8vw, 55px); font-weight: 900; }
@keyframes fadeIn { from { opacity: 0; } }

@media (max-width: 760px) {
  .app-shell { padding: 0 8px 20px; }
  .topbar { min-height: 67px; }
  .brand { min-width: 0; }
  .header-actions { flex: 0 0 auto; }
  .brand p, .icon-btn span { display: none; }
  .status-strip { margin-bottom: 7px; }
  .status-strip div { min-width: 0; padding: 6px 3px; }
  .status-strip strong { white-space: nowrap; font-size: 12px; }
  .mahjong-table { min-height: 620px; border-radius: 22px; }
  .top-player { top: 12px; width: 96%; }
  .left-player, .right-player { top: 43%; width: 116px; }
  .left-player { left: 5px; }
  .right-player { right: 5px; }
  .opponent .identity { gap: 4px; font-size: 10px; }
  .opponent .identity strong { font-size: 10px; }
  .opponent .wind-badge { width: 20px; height: 20px; font-size: 11px; }
  .tile-back { width: 18px; height: 27px; border-width: 1px; }
  .left-player .tile-backs, .right-player .tile-backs { max-width: 84px; }
  .discard-river { grid-template-columns: repeat(6, 20px); gap: 2px; min-height: 65px; margin-top: 5px; }
  .river-tile { width: 20px; height: 28px; font-size: 16px; }
  .center-board { top: 43%; width: 126px; height: 126px; border-radius: 17px; }
  .round-wind { font-size: 31px; }
  .center-info .mini-tile { width: 26px; height: 34px; font-size: 20px; }
  .turn-light, .sticks { font-size: 7px; }
  .turn-light i { width: 8px; height: 8px; }
  .bottom-player { left: 4px; right: 4px; bottom: 14px; }
  .human-meta { padding-bottom: 3px; }
  .human-hand { justify-content: flex-start; min-height: 73px; padding: 8px 4px 12px; gap: 2px; }
  .tile { width: 39px; height: 57px; font-size: 30px; }
  .tile.drawn { margin-left: 5px; }
  .message-bar { bottom: 105px; width: 88%; font-size: 11px; }
  .command-panel { position: sticky; z-index: 10; bottom: max(6px, env(safe-area-inset-bottom)); flex-direction: column; gap: 7px; min-height: 70px; padding: 8px; background: rgba(4,20,15,.95); }
  .action-btn { min-width: 62px; min-height: 40px; }
  .discard-btn { width: 100%; min-height: 45px; }
  .sub-panels { grid-template-columns: 1fr; }
  .modal { padding: 9px; }
  .modal-card { padding: 27px 18px; }
  .steps { grid-template-columns: 1fr; }
}

@media (max-width: 390px) {
  .mahjong-table { min-height: 590px; }
  .tile { width: 36px; height: 54px; font-size: 28px; }
  .center-board { top: 41%; }
  .left-player, .right-player { top: 41%; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; animation: none !important; transition: none !important; } }
