:root {
  --bg: #0f2f22;
  --felt: #17543c;
  --felt2: #1d6347;
  --panel: #fffaf0;
  --ink: #23201b;
  --muted: #7b7366;
  --line: #e4dccb;
  --accent: #c0392b;
  --blue: #2471a3;
  --gold: #d4a017;
  --tile-w: 30px;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  -webkit-text-size-adjust: 100%;
}
button {
  font: inherit;
  cursor: pointer;
  border: 1px solid #c9bfa9;
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 14px;
}
button:disabled {
  opacity: 0.45;
  cursor: default;
}
button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
button.small {
  padding: 4px 9px;
  font-size: 13px;
}
input,
select {
  font: inherit;
  padding: 7px 9px;
  border: 1px solid #c9bfa9;
  border-radius: 8px;
  background: #fff;
}
a {
  color: inherit;
}

.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 16px 40px;
}
.toplink {
  color: #cfe3d8;
  font-size: 13px;
  text-decoration: none;
}
.card {
  background: var(--panel);
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 12px;
}
h1 {
  color: #fff;
  font-size: 24px;
  margin: 10px 0 2px;
  letter-spacing: 0.05em;
}
.sub {
  color: #cfe3d8;
  font-size: 13px;
  margin: 0;
}
h2 {
  font-size: 16px;
  margin: 0 0 10px;
}
.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.muted {
  color: var(--muted);
  font-size: 13px;
}
.err {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: #2b2620;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  z-index: 50;
  font-size: 14px;
  max-width: 90vw;
}

/* ---------- ロビー ---------- */
.seats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.seat {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fff;
  min-height: 92px;
}
.seat .who {
  font-weight: bold;
}
.seat .char {
  font-size: 13px;
  color: var(--muted);
  margin: 4px 0 6px;
}
.seat.me {
  border-color: var(--accent);
}
.code {
  font-size: 28px;
  letter-spacing: 0.2em;
  font-weight: bold;
}
.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.chip {
  border: 1px solid #c9bfa9;
  border-radius: 999px;
  padding: 4px 12px;
  background: #fff;
  font-size: 14px;
}
.chip.on {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

/* ---------- キャラ選択 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 16px;
}
.modal {
  background: var(--panel);
  color: var(--ink);
  border-radius: 12px;
  width: 100%;
  max-width: 720px;
  padding: 14px 16px;
}
.school {
  margin-top: 10px;
}
.school h3 {
  font-size: 14px;
  margin: 8px 0 6px;
  color: var(--muted);
}
.charlist {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
}
.charbtn {
  text-align: left;
  padding: 7px 9px;
  font-size: 14px;
}
.charbtn.on {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent) inset;
}
.charbtn small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
  line-height: 1.35;
}
.stats {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 4px 10px;
  align-items: center;
  font-size: 14px;
}
.stars {
  color: var(--gold);
  letter-spacing: 0.02em;
  font-size: 13px;
  white-space: nowrap;
}

/* ---------- 対局 ---------- */
.game {
  max-width: 980px;
  margin: 0 auto;
  padding: 6px 8px 24px;
  color: #fff;
}
.topbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 14px;
}
.topbar .label {
  font-weight: bold;
  font-size: 16px;
}
.table {
  position: relative;
  background: radial-gradient(circle at 50% 45%, var(--felt2), var(--felt));
  border-radius: 14px;
  margin-top: 6px;
  padding: 8px;
  display: grid;
  grid-template-columns: 1fr minmax(0, 2.2fr) 1fr;
  grid-template-rows: auto auto auto;
  gap: 6px;
  min-height: 360px;
}
.opp {
  font-size: 12px;
}
.opp.top {
  grid-column: 2;
  grid-row: 1;
}
.opp.left {
  grid-column: 1;
  grid-row: 2;
}
.opp.right {
  grid-column: 3;
  grid-row: 2;
}
.center {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  justify-content: center;
}
.selfriver {
  grid-column: 2;
  grid-row: 3;
}
.nameplate {
  background: rgba(0, 0, 0, 0.28);
  border-radius: 8px;
  padding: 4px 7px;
  display: flex;
  gap: 6px;
  align-items: baseline;
  flex-wrap: wrap;
}
.nameplate.turn {
  outline: 2px solid var(--gold);
}
.nameplate .score {
  font-variant-numeric: tabular-nums;
  font-weight: bold;
}
.nameplate .tag {
  font-size: 11px;
  border-radius: 4px;
  padding: 0 4px;
  background: rgba(255, 255, 255, 0.18);
}
.nameplate .tag.riichi {
  background: var(--accent);
}
.nameplate .tag.tenpai {
  background: var(--blue);
}
.nameplate .tag.dealer {
  background: var(--gold);
  color: #000;
}
.river {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  margin-top: 4px;
  max-width: calc(var(--tile-w) * 0.8 * 6 + 8px);
}
.selfriver .river,
.opp.top .river {
  max-width: none;
}
.melds {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 3px;
}
.meld {
  display: flex;
  gap: 0;
  align-items: flex-end;
}
.backs {
  display: flex;
  gap: 1px;
  margin-top: 3px;
  flex-wrap: wrap;
}
.back {
  width: 12px;
  height: 17px;
  border-radius: 2px;
  background: linear-gradient(#e2a248, #b77a26);
  border: 1px solid #7a5218;
}
.back.m {
  background: #e05a4f;
}
.back.p {
  background: #3f86c7;
}
.back.s {
  background: #3fa36a;
}
.back.z {
  background: #ddd;
}
.tile {
  display: inline-block;
  position: relative;
  line-height: 0;
  border-radius: 3px;
}
.tile img {
  width: var(--tile-w);
  height: auto;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}
.tile.sm img {
  width: calc(var(--tile-w) * 0.8);
}
.tile.xs img {
  width: calc(var(--tile-w) * 0.62);
}
.tile.side img {
  width: calc(var(--tile-w) * 0.8 * 1.33);
}
.tile.called {
  opacity: 0.35;
}
.tile.danger::after,
.tile.blue::after,
.tile.bust::after,
.tile.red::after,
.tile.orange::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 3px;
  pointer-events: none;
}
.tile.danger::after {
  box-shadow: 0 0 0 2px #e74c3c inset;
}
.tile.bust::after {
  box-shadow: 0 0 0 3px #8e44ad inset;
}
.tile.blue::after {
  box-shadow: 0 0 0 2px #3498db inset;
  background: rgba(52, 152, 219, 0.18);
}
.tile.red::after {
  box-shadow: 0 0 0 2px #e74c3c inset;
  background: rgba(231, 76, 60, 0.15);
}
.tile.orange::after {
  box-shadow: 0 0 0 2px #f39c12 inset;
  background: rgba(243, 156, 18, 0.15);
}
.hand {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding: 6px 2px 4px;
}
.hand .tile {
  cursor: pointer;
  transition: transform 0.08s;
}
.hand .tile.can:hover {
  transform: translateY(-5px);
}
.hand .tile.dim {
  opacity: 0.45;
  cursor: default;
}
.hand .tile.riichiable {
  transform: translateY(-4px);
}
.hand .gap {
  width: 10px;
  flex: none;
}
.selfbar {
  margin-top: 6px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 12px;
  padding: 6px 8px;
}
.actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.actions button {
  padding: 7px 12px;
}
.actions button.on {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.timer {
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}
.timer > div {
  height: 100%;
  background: var(--gold);
}
.dora {
  display: flex;
  gap: 2px;
  align-items: center;
}
.infobox {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 13px;
  text-align: center;
}
.ability {
  margin-top: 6px;
  background: var(--panel);
  color: var(--ink);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 13px;
}
.ability .head {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.gauge {
  flex: 1;
  min-width: 90px;
  height: 8px;
  background: #e8e0cf;
  border-radius: 4px;
  overflow: hidden;
}
.gauge > div {
  height: 100%;
  background: linear-gradient(90deg, #8e44ad, #c0392b);
}
.ability .lines div {
  margin-top: 4px;
}
.ability .tiles {
  display: inline-flex;
  gap: 2px;
  vertical-align: middle;
}
.result {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
.result .modal {
  max-width: 560px;
}
.yaku {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  font-size: 14px;
  margin: 6px 0;
}
.delta {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 2px 10px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.plus {
  color: #1e8449;
}
.minus {
  color: #c0392b;
}

@media (max-width: 640px) {
  :root {
    --tile-w: 24px;
  }
  .table {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto auto;
  }
  .opp.top {
    grid-column: 1 / 3;
    grid-row: 1;
  }
  .opp.left {
    grid-column: 1;
    grid-row: 2;
  }
  .opp.right {
    grid-column: 2;
    grid-row: 2;
  }
  .center {
    grid-column: 1 / 3;
    grid-row: 3;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .selfriver {
    grid-column: 1 / 3;
    grid-row: 4;
  }
  .seats {
    grid-template-columns: 1fr;
  }
}
.optbox {
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 8px;
  background: #fff;
}
.seg {
  display: inline-flex;
  border: 1px solid #c9bfa9;
  border-radius: 8px;
  overflow: hidden;
}
.seg button {
  border: none;
  border-radius: 0;
  padding: 4px 12px;
  font-size: 13px;
  background: #fff;
}
.seg button + button {
  border-left: 1px solid #c9bfa9;
}
.seg button.on {
  background: var(--ink);
  color: #fff;
}
.optstate {
  font-weight: bold;
  font-size: 13px;
}
.optstate.yes {
  color: var(--accent);
}
.optstate.no {
  color: var(--muted);
}
button.help {
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 50%;
  font-size: 12px;
  line-height: 18px;
  margin-left: 4px;
  vertical-align: middle;
}
.helptext {
  grid-column: 1 / -1;
  font-size: 13px;
  color: var(--muted);
  background: #f4efe3;
  border-radius: 8px;
  padding: 6px 9px;
  line-height: 1.5;
}
.overlay.solid {
  background: var(--bg);
  padding: 0;
}
