* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --felt: #1d6b45;
  --felt-dark: #14532f;
  --tile-w: clamp(26px, 6.4vw, 44px);
  --tile-h: calc(var(--tile-w) * 1.38);
  --small-w: clamp(17px, 4.3vw, 29px);
  --small-h: calc(var(--small-w) * 1.38);
}
html, body { height: 100%; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  background: #0c2e1e;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.topbar {
  width: min(96vw, 560px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 2px 4px;
  font-size: 14px;
}
.topbar .title { font-weight: 700; font-size: 16px; }
.round-info { background: rgba(255,255,255,.14); padding: 2px 10px; border-radius: 999px; }
.dora-box { display: flex; align-items: center; gap: 5px; margin-left: auto; }
.dora-label { font-size: 11px; opacity: .85; }
.wall-info { font-size: 12px; opacity: .85; }

.table {
  position: relative;
  width: min(96vw, 560px);
  aspect-ratio: 1 / 1;
  background: radial-gradient(circle at 50% 45%, var(--felt) 0%, var(--felt-dark) 78%);
  border-radius: 14px;
  box-shadow: inset 0 0 0 6px #0a3d24, 0 6px 24px rgba(0,0,0,.5);
  margin-top: 4px;
}
.center-box {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 27%;
  aspect-ratio: 1 / 1;
  background: rgba(0,0,0,.28);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
  padding: 4px;
}
.center-round { font-size: clamp(15px, 4.6vw, 22px); font-weight: 700; }
.center-sub { font-size: clamp(10px, 3vw, 13px); opacity: .9; line-height: 1.5; }

/* 河（捨て牌） */
.pond {
  position: absolute;
  display: grid;
  grid-template-columns: repeat(6, var(--small-w));
  gap: 2px;
  justify-content: center;
}
.pond-bottom { left: 50%; bottom: 15.5%; transform: translateX(-50%); }
.pond-top { left: 50%; top: 15.5%; transform: translateX(-50%) rotate(180deg); }
.pond-left { left: 15.5%; top: 50%; transform: translateY(-50%) rotate(90deg); transform-origin: center; width: max-content; }
.pond-right { right: 15.5%; top: 50%; transform: translateY(-50%) rotate(-90deg); transform-origin: center; width: max-content; }
.pond .tile.called { opacity: .45; }
.pond .tile.riichi-discard { transform: rotate(90deg); }

/* 相手の手牌（裏向き） */
.backs { position: absolute; display: flex; gap: 1px; }
.backs-top { left: 50%; top: 1.6%; transform: translateX(-50%); }
.backs-left { left: 1.6%; top: 50%; transform: translateY(-50%); flex-direction: column; }
.backs-right { right: 1.6%; top: 50%; transform: translateY(-50%); flex-direction: column; }
.backs-left .tile.back, .backs-right .tile.back { width: var(--small-h); height: var(--small-w); }

/* 副露 */
.melds { position: absolute; display: flex; gap: 4px; }
.melds-bottom { display: flex; gap: 4px; }
.melds-top { right: 2%; top: 9%; transform: rotate(180deg); }
.melds-left { left: 2%; bottom: 9%; transform: rotate(90deg); transform-origin: bottom left; }
.melds-right { right: 2%; top: 9%; transform: rotate(-90deg); transform-origin: top right; }
.meld-group { display: flex; gap: 1px; background: rgba(0,0,0,.18); padding: 2px; border-radius: 4px; }
.meld-group .tile.called-tile { transform: rotate(90deg); margin: 0 4px; }

/* プレイヤーチップ */
.chip {
  position: absolute;
  background: rgba(0,0,0,.45);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 8px;
  padding: 3px 8px;
  font-size: clamp(10px, 2.9vw, 13px);
  line-height: 1.45;
  text-align: center;
  min-width: 86px;
  z-index: 3;
}
.chip .wind { display: inline-block; background: #b03a2e; border-radius: 4px; padding: 0 5px; margin-right: 4px; font-weight: 700; }
.chip .score { font-weight: 700; }
.chip.active { border-color: #ffd94d; box-shadow: 0 0 0 2px #ffd94d, 0 0 14px rgba(255,217,77,.7); }
.chip .riichi-stick { display: none; margin-top: 2px; }
.chip.riichi .riichi-stick { display: block; }
.riichi-stick-bar { height: 5px; background: #f5f5f5; border-radius: 3px; position: relative; }
.riichi-stick-bar::after { content: ""; position: absolute; left: 50%; top: 50%; width: 5px; height: 5px; background: #d42a2a; border-radius: 50%; transform: translate(-50%,-50%); }
.chip-bottom { left: 50%; bottom: 1.2%; transform: translateX(-50%); }
.chip-top { left: 50%; top: 8.6%; transform: translateX(-50%); }
.chip-left { left: 1.2%; top: 50%; transform: translateY(-50%); }
.chip-right { right: 1.2%; top: 50%; transform: translateY(-50%); }

/* 牌 */
.tile {
  width: var(--tile-w);
  height: var(--tile-h);
  background: linear-gradient(#ffffff, #f0ead8);
  border-radius: 12%;
  box-shadow: 0 2px 0 #b8ad8f, 0 3px 4px rgba(0,0,0,.35);
  color: #1c1c1c;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.02;
  font-weight: 700;
  position: relative;
  flex: none;
}
.tile.small { width: var(--small-w); height: var(--small-h); box-shadow: 0 1px 0 #b8ad8f; }
.tile .num { font-size: calc(var(--tile-w) * .44); }
.tile .suit { font-size: calc(var(--tile-w) * .44); }
.tile.small .num, .tile.small .suit { font-size: calc(var(--small-w) * .46); }
.tile .honor { font-size: calc(var(--tile-w) * .62); }
.tile.small .honor { font-size: calc(var(--small-w) * .64); }
.tile.man .suit { color: #20303e; }
.tile.pin .num, .tile.pin .suit { color: #1d4f9c; }
.tile.sou .num, .tile.sou .suit { color: #1e7a34; }
.tile .honor.haku { color: #1d4f9c; }
.tile .honor.hatsu { color: #1e7a34; }
.tile .honor.chun { color: #c22727; }
.tile.red .num, .tile.red .suit { color: #c22727 !important; }
.tile.back {
  background: linear-gradient(135deg, #e8930c, #c96a00);
  box-shadow: 0 2px 0 #8a4d00, 0 3px 4px rgba(0,0,0,.35);
  width: var(--small-w);
  height: var(--small-h);
}
.tile.kan-closed { filter: brightness(.75); }

/* 操作エリア */
.control {
  width: min(96vw, 560px);
  padding: 8px 2px 18px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.status-line { min-height: 20px; font-size: 14px; text-align: center; }
.status-line .waits { color: #ffd94d; font-weight: 700; }
.status-line .furiten { color: #ff8a7a; font-weight: 700; }
.action-bar {
  min-height: 44px;
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.action-bar button {
  font-size: 16px;
  font-weight: 700;
  padding: 9px 18px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  background: #f3f0e6;
  color: #20303e;
  box-shadow: 0 3px 0 rgba(0,0,0,.35);
}
.action-bar button.primary { background: #e8b400; color: #241a00; }
.action-bar button.danger { background: #c0392b; color: #fff; }
.action-bar button:active { transform: translateY(2px); box-shadow: none; }
.hand-row { display: flex; align-items: flex-end; gap: 8px; justify-content: center; }
.my-hand { display: flex; gap: 2px; justify-content: center; flex-wrap: nowrap; }
.my-hand .tile { cursor: pointer; transition: transform .08s; }
.my-hand .tile:hover { transform: translateY(-5px); }
.my-hand .tile.drawn { margin-left: 8px; }
.my-hand .tile.selectable { box-shadow: 0 2px 0 #b8ad8f, 0 0 0 2px #ffd94d; }
.my-hand .tile.dim { opacity: .45; }
.my-hand .tile:where(.not-selectable) { cursor: default; }
.my-melds { display: flex; gap: 4px; }

/* モーダル */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.66);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 14px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: #123f27;
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 14px;
  padding: 18px;
  width: min(94vw, 480px);
  max-height: 88vh;
  overflow-y: auto;
  text-align: center;
}
.modal-card h2 { font-size: 20px; margin-bottom: 8px; }
.modal-card .win-hand { display: flex; gap: 2px; justify-content: center; margin: 10px 0; flex-wrap: wrap; }
.modal-card .yaku-list { text-align: left; margin: 8px auto; width: fit-content; font-size: 15px; line-height: 1.7; }
.modal-card .yaku-list .dora-line { color: #ffd94d; }
.modal-card .total-line { font-size: 18px; font-weight: 700; margin: 6px 0; }
.modal-card .score-table { margin: 10px auto; font-size: 14px; border-collapse: collapse; }
.modal-card .score-table td { padding: 3px 10px; text-align: left; }
.modal-card .score-table td:last-child { text-align: right; font-weight: 700; }
.modal-card .delta-plus { color: #8be08b; }
.modal-card .delta-minus { color: #ff9a8a; }
.modal-btn {
  margin-top: 12px;
  font-size: 16px;
  font-weight: 700;
  padding: 10px 26px;
  border-radius: 999px;
  border: none;
  background: #e8b400;
  color: #241a00;
  cursor: pointer;
}
