:root {
  --felt: #14532d;
  --felt-deep: #0c3a1f;
  --felt-line: #2a7a48;
  --ink: #f3f1e7;
  --ink-dim: #b9c9bd;
  --gold: #f2c14e;
  --pink: #ff6fa5;
  --hot: #ff3b5c;
  --tile: #fbf8ee;
  --tile-edge: #cfc7ad;
  --tile-back: #d98a1f;
  --panel: rgba(0, 0, 0, 0.28);
  --tw: clamp(26px, 5.4vw, 46px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at 50% 30%, var(--felt) 0%, var(--felt-deep) 100%) fixed;
  color: var(--ink);
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  font-size: 14px;
  -webkit-user-select: none; user-select: none;
}
#app { max-width: 1100px; margin: 0 auto; padding: 10px 12px 12px; }
button {
  font: inherit; color: #1b1b1b; background: #f3f1e7; border: 0; border-radius: 8px;
  padding: 8px 14px; cursor: pointer; font-weight: 600;
}
button:hover { filter: brightness(1.08); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--gold); }
button.hot { background: var(--hot); color: #fff; }
button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--felt-line); }
button.on { outline: 3px solid var(--gold); }

/* ---------- 牌 ---------- */
.tile {
  width: var(--tw); height: calc(var(--tw) * 1.36); flex: none;
  background: linear-gradient(180deg, #fffdf6, #f4efdf); border-radius: calc(var(--tw) * .13);
  /* 白い牌の下に、背の色（橙）の層がのぞく */
  box-shadow: 0 calc(var(--tw) * .05) 0 #e6dfc8, 0 calc(var(--tw) * .12) 0 #d98a1f, 0 calc(var(--tw) * .16) calc(var(--tw) * .1) rgba(0, 0, 0, .4);
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  line-height: 1; position: relative; color: #222; font-weight: 700;
}
.tile .face { width: 86%; height: 90%; display: block; pointer-events: none; }
/* 7筒・7索（確変の牌）はピンク、ドラは金。両方なら半々 */
.tile.lucky { background: #ffc9e0; }
.tile.dora { background: #ffe08a; }
.tile.red { background: linear-gradient(180deg, #fffdf6, #f4efdf); }
.tile.red.lucky { background: #ffc9e0; }
.tile.red.dora { background: #ffe08a; }
.tile.lucky.dora { background: linear-gradient(135deg, #ffc9e0 50%, #ffe08a 50%); }
.tile.back { background: linear-gradient(160deg, #f0a431, var(--tile-back)); box-shadow: 0 2px 0 #9a5f10, 0 3px 4px rgba(0, 0, 0, .35); }
.tile.wild { background: linear-gradient(160deg, #fff7c9, #ffd9ec); color: #b0127a; }
.tile.wild .star { font-size: calc(var(--tw) * .5); }
.tile.wild .lbl { font-size: calc(var(--tw) * .2); }
.tile.wildmark::before {
  content: "★"; position: absolute; top: 0; left: 2px; font-size: calc(var(--tw) * .26); color: #d0168f;
}
.tile.wildmark { background: #fff3fb; }
.tile.sm { --tw: clamp(18px, 3.5vw, 28px); }
.tile.xs { --tw: clamp(11px, 2vw, 16px); }
.tile.side { transform: rotate(90deg); margin: 0 calc(var(--tw) * .2); }
.tile.dim { opacity: .35; }
.tile.last { outline: 3px solid var(--gold); }
.tile.hit { outline: 3px solid var(--pink); transform: translateY(-6px); }
.tiles { display: flex; flex-wrap: wrap; gap: 2px; align-items: flex-end; }
.gap { width: calc(var(--tw) * .35); flex: none; }

/* ---------- 卓（論理座標 1000×1000） ---------- */
.stage {
  position: relative; margin: 0 auto; overflow: hidden; border-radius: 18px;
  background: radial-gradient(ellipse at 50% 45%, #1b6b3b 0%, #0f4a27 70%, #0b3a1f 100%);
  box-shadow: 0 0 0 6px #5a3a1a, 0 0 0 9px #2e1c0b, 0 12px 30px rgba(0, 0, 0, .5);
}
.stage.zoom.lv1 { box-shadow: 0 0 0 6px var(--pink), 0 0 40px rgba(255, 111, 165, .6); }
.stage.zoom.lv2 { box-shadow: 0 0 0 6px var(--gold), 0 0 46px rgba(242, 193, 78, .7); }
.table {
  position: absolute; left: 0; top: 0; width: 1000px; height: 1000px;
  transform-origin: 0 0; transition: transform 1.1s cubic-bezier(.6, 0, .2, 1);
  font-size: 18px;
}
.table .tile { --tw: 34px; }
.table .wt { position: absolute; }
.table .wt.w2 { box-shadow: 0 5px 0 #9a5f10, 0 7px 6px rgba(0, 0, 0, .45); }
.table .wt.w1 { box-shadow: 0 2px 0 #9a5f10, 0 3px 4px rgba(0, 0, 0, .4); }
.seat { position: absolute; inset: 0; transform-origin: 500px 500px; pointer-events: none; }
.seat.pos1 { transform: rotate(-90deg); }
.seat.pos2 { transform: rotate(90deg); }
.sriver { position: absolute; left: 398px; top: 612px; }
.rrow { display: flex; height: 48px; align-items: flex-start; }
.rrow .tile.side { transform: rotate(90deg); margin: 0 6px; }
.stick {
  position: absolute; left: 430px; top: 599px; width: 140px; height: 9px; border-radius: 4px;
  background: #f6f3ea; box-shadow: 0 1px 2px rgba(0, 0, 0, .5);
}
.stick::after { content: ""; position: absolute; left: 66px; top: 2px; width: 6px; height: 5px; border-radius: 50%; background: #d81b3a; }
.sside { position: absolute; top: 862px; left: 262px; right: 20px; display: flex; gap: 12px; }
.skita { display: flex; gap: 1px; }
.smelds { display: flex; gap: 10px; }
.seat.me .smelds { margin-left: auto; }
.meld { display: flex; gap: 1px; }
.shand { position: absolute; left: 0; right: 0; display: flex; justify-content: center; gap: 1px; align-items: flex-end; }
.seat.opp .shand { top: 936px; }
.seat.opp .shand .tile { --tw: 30px; }
.seat.me .shand { top: 912px; }
.seat.me .shand .tile { --tw: 52px; pointer-events: auto; }
.seat.me .shand .tile.can { cursor: pointer; transition: transform .08s; }
.seat.me .shand .tile.can:hover { transform: translateY(-12px); }
.plate {
  position: absolute; display: flex; align-items: center; gap: 8px; white-space: nowrap;
  background: rgba(0, 0, 0, .38); border: 2px solid transparent; border-radius: 10px; padding: 5px 10px;
}
.plate.active { border-color: var(--gold); }
/* 名札は手牌より内側。相手は牌山の角（上辺の山と左右の山の間）に置く */
.plate0 { left: 16px; top: 862px; }
.plate2 { left: 80px; top: 204px; }
.plate1 { right: 80px; top: 204px; }
.wind {
  width: 26px; height: 26px; border-radius: 50%; background: #f3f1e7; color: #1b1b1b;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 800; flex: none;
}
.wind.dealer { background: var(--hot); color: #fff; }
.pname { font-weight: 700; }
.chips { font-variant-numeric: tabular-nums; color: var(--gold); font-weight: 700; }
.chips::before {
  content: ""; display: inline-block; width: .7em; height: .7em; border-radius: 50%;
  background: var(--gold); border: 2px dashed #8a6410; margin-right: 4px; vertical-align: -1px;
}
.chips.neg { color: #ff9c9c; }
.badge { background: var(--hot); color: #fff; border-radius: 4px; padding: 1px 6px; font-size: .85em; font-weight: 700; }
.center {
  position: absolute; left: 400px; top: 400px; width: 200px; height: 196px; border-radius: 14px;
  background: #0a2715; border: 2px solid #2a7a48; box-shadow: inset 0 0 18px rgba(0, 0, 0, .6);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.cround { font-size: 23px; font-weight: 800; letter-spacing: .04em; }
.cround small { font-size: 14px; font-weight: 600; color: var(--ink-dim); }
.cinfo { font-size: 13px; color: var(--ink-dim); }
.cdora { display: flex; align-items: center; gap: 3px; font-size: 13px; color: var(--ink-dim); margin-bottom: 22px; }
.cdora .tile { --tw: 22px; }
.cs {
  position: absolute; font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums;
  display: flex; align-items: center; gap: 5px; white-space: nowrap; color: var(--ink);
}
.cs.active { color: var(--gold); }
.cs .cw { font-size: 13px; background: #f3f1e7; color: #1b1b1b; border-radius: 4px; padding: 0 4px; }
.cs .cw.dealer { background: var(--hot); color: #fff; }
.cs-b { bottom: 5px; left: 50%; transform: translateX(-50%); }
.cs-l { left: 14px; top: 50%; transform: translate(-50%, -50%) rotate(90deg); }
.cs-r { right: 14px; top: 50%; transform: translate(50%, -50%) rotate(-90deg); }

.tulayer { position: absolute; inset: 0; pointer-events: none; }
.tulayer .tile { pointer-events: auto; }
.tulayer .tile.tf { box-shadow: 0 2px 0 var(--tile-edge), 0 0 0 2px rgba(255, 255, 255, .5), 0 4px 6px rgba(0, 0, 0, .5); }
.tulayer .tile.next { animation: pulse 1s infinite; }
.tulayer .tile.next.mine { cursor: pointer; }
.tulayer .tile.flip { animation: flip .4s ease-out; }
.tres { position: absolute; width: 60px; text-align: center; font-size: 15px; font-weight: 900; line-height: 20px; text-shadow: 0 1px 3px #000; }
.tres.hitv { color: #ffd0e2; }
.tres.miss { color: #cfd8d2; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(242, 193, 78, .9), 0 3px 4px rgba(0, 0, 0, .35); } }
@keyframes flip { from { transform: rotateY(90deg) scale(1.2); } to { transform: none; } }

.hud {
  position: absolute; left: 10px; right: 10px; bottom: 10px; padding: 10px 12px; border-radius: 12px;
  background: rgba(8, 26, 15, .9); border: 2px solid var(--felt-line);
}
.hud[hidden] { display: none; }
.hud.lv1 { border-color: var(--pink); }
.hud.lv2 { border-color: var(--gold); }
.hud .thead { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.hud .hudhand { margin: 12px 0 6px; }
.mode { font-weight: 800; padding: 3px 10px; border-radius: 999px; background: #f3f1e7; color: #1b1b1b; }
.mode.lv1 { background: var(--pink); color: #fff; }
.mode.lv2 { background: var(--gold); color: #1b1b1b; }
.stock { color: var(--ink-dim); }
.stock b { color: var(--ink); }
.tsum { margin-left: auto; font-size: 22px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
.tmsg { min-height: 24px; font-weight: 800; margin-bottom: 6px; }
.tmsg.big { color: var(--gold); font-size: 18px; animation: pop .4s; }
@keyframes pop { from { transform: scale(1.4); } to { transform: none; } }

.dock { margin: 8px auto 0; display: flex; align-items: center; gap: 10px; }
.dock .status { flex: 1; }
.status { min-height: 34px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--ink-dim); }
.status b { color: var(--ink); }
.status .furiten { color: #ff9c9c; font-weight: 700; }
.actions { display: flex; gap: 8px; min-height: 40px; align-items: center; }
.actions .hint { color: var(--ink-dim); }
.actions .quit { margin-left: auto; }

/* ---------- タイトル ---------- */
.title { max-width: 640px; margin: 0 auto; }
.title h1 { font-size: clamp(22px, 5vw, 34px); margin: 18px 0 2px; letter-spacing: .04em; }
.title h1 em { font-style: normal; color: var(--pink); }
.title .sub { color: var(--ink-dim); margin: 0 0 16px; }
.card { background: var(--panel); border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; }
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--gold); }
.chiprow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.chipbox { background: rgba(0, 0, 0, .25); border-radius: 8px; padding: 8px; text-align: center; }
.chipbox .big { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--gold); }
.chipbox .diff { font-size: 12px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.row { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.row label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
input[type=number] { width: 72px; font: inherit; padding: 5px 6px; border-radius: 6px; border: 0; }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--gold); }
details { color: var(--ink-dim); }
details summary { cursor: pointer; color: var(--ink); font-weight: 700; }
details li { margin: 4px 0; line-height: 1.6; }
details b { color: var(--ink); }

/* ---------- 結果 ---------- */
#overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .62); overflow: auto;
  display: flex; align-items: flex-start; justify-content: center; padding: 16px 10px;
}
#overlay[hidden] { display: none; }
.modal {
  background: #123b22; border: 1px solid var(--felt-line); border-radius: 14px;
  width: 100%; max-width: 760px; padding: 16px 18px; box-shadow: 0 20px 50px rgba(0, 0, 0, .5);
}
.modal h2 { margin: 0 0 10px; font-size: 20px; }
.modal h3 { margin: 16px 0 6px; font-size: 14px; color: var(--gold); }
.yaku { display: grid; grid-template-columns: 1fr auto; gap: 2px 16px; max-width: 320px; }
.yaku .h { text-align: right; font-variant-numeric: tabular-nums; }
.total { font-size: 18px; font-weight: 800; margin-top: 8px; }
table.pay { border-collapse: collapse; width: 100%; max-width: 520px; }
table.pay td, table.pay th { padding: 3px 8px; text-align: right; font-variant-numeric: tabular-nums; }
table.pay th { color: var(--ink-dim); font-weight: 500; }
table.pay td:first-child, table.pay th:first-child { text-align: left; }
.plus { color: #8ff0a8; font-weight: 700; }
.minus { color: #ff9c9c; font-weight: 700; }
.inds { display: flex; flex-wrap: wrap; gap: 4px 18px; align-items: center; margin-top: 8px; color: var(--ink-dim); }
.inds .tiles { display: inline-flex; }

.tease { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-top: 14px; padding: 10px 12px; border-radius: 10px; background: rgba(0, 0, 0, .3); border: 2px solid transparent; }
.tease.lv1 { border-color: var(--pink); }
.tease.lv2 { border-color: var(--gold); }
button.big { font-size: 17px; padding: 11px 22px; }
.modal .foot { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.chipitems { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.rank1 { color: var(--gold); font-weight: 800; }

@media (max-width: 520px) {
  body { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  .tulayer .tile.flip, .tmsg.big, .tulayer .tile.next { animation: none; }
  .table { transition: none; }
}

/* ---------- 吹き出し ---------- */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.callout {
  position: absolute; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center;
  padding: 8px 22px 10px; border-radius: 22px; background: #fffdf4; color: #1b1b1b;
  border: 4px solid #1b1b1b; box-shadow: 0 8px 22px rgba(0, 0, 0, .5);
  animation: callout-in .28s cubic-bezier(.2, 1.6, .4, 1), callout-out .3s ease-in 1s forwards;
}
.callout .who { font-size: 12px; font-weight: 700; color: #666; }
.callout .what { font-size: clamp(30px, 6vw, 52px); font-weight: 900; line-height: 1.1; letter-spacing: .06em; }
/* しっぽ: 自分は下向き、下家は右向き、上家は左向き */
.callout::after { content: ""; position: absolute; width: 20px; height: 20px; background: inherit; border: inherit; border-top: 0; border-left: 0; }
.callout.seat0::after { bottom: -14px; left: 50%; transform: translateX(-50%) rotate(45deg); }
.callout.seat1::after { right: -14px; top: 50%; transform: translateY(-50%) rotate(-45deg); }
.callout.seat2::after { left: -14px; top: 50%; transform: translateY(-50%) rotate(135deg); }
.callout.riichi { background: #ff3b5c; color: #fff; border-color: #fff; animation-duration: .28s, .3s; animation-delay: 0s, 1.4s; }
.callout.riichi .who { color: #ffd9e0; }
.callout.win { background: #f2c14e; border-color: #fff; animation-delay: 0s, 1.4s; }
.callout.win .who { color: #6b4a00; }
.callout.win .what { font-size: clamp(38px, 8vw, 68px); }
@keyframes callout-in { from { transform: translate(-50%, -50%) scale(.2); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
@keyframes callout-out { to { transform: translate(-50%, -80%) scale(.9); opacity: 0; } }
#app.flash-riichi .stage { animation: flash-red .7s; }
#app.flash-win .stage { animation: flash-gold .7s; }
@keyframes flash-red { 30% { box-shadow: 0 0 0 6px #ff3b5c, 0 0 60px 10px rgba(255, 59, 92, .8); } }
@keyframes flash-gold { 30% { box-shadow: 0 0 0 6px #f2c14e, 0 0 60px 10px rgba(242, 193, 78, .9); } }
@media (prefers-reduced-motion: reduce) { .callout { animation: none; } #app.flash-riichi .stage, #app.flash-win .stage { animation: none; } }

/* ---------- 卓上の操作ボタン（手牌の右上） ---------- */
.onboard {
  position: absolute; right: 2.5%; bottom: 16%; z-index: 5; max-width: 70%;
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; align-items: center;
  padding: 8px; border-radius: 14px; background: rgba(6, 22, 12, .72);
}
.onboard button { font-size: clamp(15px, 2.6vw, 20px); padding: 10px 18px; box-shadow: 0 3px 0 rgba(0, 0, 0, .45); }
.onboard button.ghost { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .5); }
.legend { margin-left: auto; color: var(--ink-dim); font-size: 12px; display: inline-flex; align-items: center; gap: 4px; }
.lg { display: inline-block; width: 12px; height: 16px; border-radius: 2px; margin-left: 8px; }
.lg.lucky { background: #ffc9e0; }
.lg.dora { background: #ffe08a; }
.actions .legend + .quit { margin-left: 8px; }
/* チューリップのズーム中は名札を隠す（めくる山の邪魔になるため） */
.plate { transition: opacity .3s; }
.stage.zoom .plate { opacity: 0; }

select { font: inherit; padding: 6px 8px; border-radius: 6px; border: 0; max-width: 100%; }
.note { color: var(--ink-dim); margin: 8px 0 0; line-height: 1.6; }

/* ---------- 友人戦 ---------- */
input[type=text] { font: inherit; padding: 5px 8px; border-radius: 6px; border: 0; width: 150px; }
input.codein { width: 96px; letter-spacing: .18em; text-align: center; font-variant-numeric: tabular-nums; }
.neterr { color: #ff9c9c; font-weight: 700; margin: 8px 0 0; min-height: 1.2em; }
.codecard { text-align: center; }
.roomcode { font-size: clamp(40px, 11vw, 72px); font-weight: 900; letter-spacing: .14em; color: var(--gold); font-variant-numeric: tabular-nums; line-height: 1.15; -webkit-user-select: text; user-select: text; }
.chipbox.you { outline: 2px solid var(--gold); }
.chipbox .badge { margin-left: 4px; }
.badge.gray { background: rgba(255, 255, 255, .22); }
button.small { font-size: 12px; padding: 4px 8px; margin-top: 6px; }
.hint { color: var(--ink-dim); }
.countdown { color: #ffb3b3; font-weight: 800; font-variant-numeric: tabular-nums; }
.toast {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); max-width: 90vw;
  background: rgba(20, 20, 20, .92); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 700;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .5);
}

/* ---------- 確認ダイアログ ---------- */
#ask { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; padding: 16px; }
#ask[hidden] { display: none; }
.askbox { background: #123b22; border: 1px solid var(--felt-line); border-radius: 14px; max-width: 460px; width: 100%; padding: 18px; box-shadow: 0 20px 50px rgba(0, 0, 0, .6); }
.askbox p { margin: 0 0 4px; line-height: 1.7; font-size: 15px; }
.askbox .foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
