:root {
  --felt: #1b4d3e;
  --felt-deep: #0f2e26;
  --ink: #f2ebe0;
  --muted: #b7c4b8;
  --panel: rgba(12, 28, 24, 0.72);
  --line: rgba(242, 235, 224, 0.14);
  --accent: #e2b857;
  --accent-ink: #1a1406;
  --danger: #ff8f7a;
  --seat-jicha: #4ea1ff;
  --seat-shimocha: #e8c547;
  --seat-toimen: #f07178;
  --seat-kamicha: #c084fc;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "Zen Kaku Gothic New", "Hiragino Sans", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--felt-deep);
  line-height: 1.45;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(226, 184, 87, 0.18), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 80%, rgba(60, 140, 110, 0.35), transparent 50%),
    linear-gradient(165deg, #163d32 0%, var(--felt-deep) 45%, #0a1c18 100%);
}
.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80'%3E%3Cpath d='M0 40h80M40 0v80' stroke='%23fff' stroke-width='.5' fill='none'/%3E%3C/svg%3E");
}

.hero {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2.75rem 1.25rem 1.25rem;
  animation: rise 0.7s ease both;
}

.brand {
  margin: 0;
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  font-weight: 900;
  letter-spacing: 0.02em;
  line-height: 1.05;
  color: var(--accent);
}

.tagline {
  margin: 0.55rem 0 0;
  font-size: clamp(1.05rem, 2.4vw, 1.35rem);
  font-weight: 700;
}

.lede {
  margin: 0.45rem 0 0;
  max-width: 42rem;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.55;
  word-break: keep-all;
  overflow-wrap: break-word;
  line-break: strict;
}

.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 1.25rem 3.5rem;
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 960px) {
  .shell {
    grid-template-columns: 1.45fr 0.85fr;
    align-items: start;
  }

  .kyoku-form-grid {
    display: contents;
  }

  .board-block {
    grid-column: 1 / -1;
  }

  .side {
    grid-row: 2;
    grid-column: 2;
  }
}

.block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem 1.1rem 1.15rem;
  margin-bottom: 0.85rem;
  backdrop-filter: blur(8px);
  animation: rise 0.75s ease both;
}

.block:nth-child(2) { animation-delay: 0.05s; }
.block:nth-child(3) { animation-delay: 0.1s; }
.block:nth-child(4) { animation-delay: 0.15s; }
.block:nth-child(5) { animation-delay: 0.2s; }

.block h2 {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 0.65rem 0.85rem;
}

.grid-round {
  grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
}

.grid-scores,
.grid-seats {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (min-width: 640px) {
  .grid-scores,
  .grid-seats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.span-2 {
  grid-column: span 2;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}

label.full {
  width: 100%;
}

input,
select {
  font: 600 0.92rem/1.3 var(--sans);
  color: var(--ink);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  width: 100%;
}

input:focus,
select:focus {
  outline: 2px solid rgba(226, 184, 87, 0.55);
  outline-offset: 1px;
}

input.mono,
.mono {
  font-family: var(--mono);
  font-weight: 400;
  letter-spacing: 0.02em;
}

input.wide {
  font-size: 1rem;
  padding: 0.65rem 0.7rem;
}

.hint {
  margin: 0 0 0.65rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.hint code,
code {
  font-family: var(--mono);
  font-size: 0.85em;
  color: var(--accent);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.35rem;
  animation: rise 0.8s ease both;
  animation-delay: 0.25s;
}

.actions-main {
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
  margin: 0 0 0.85rem;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  border: 1px solid rgba(226, 184, 87, 0.35);
  background: linear-gradient(
    165deg,
    rgba(226, 184, 87, 0.12),
    rgba(16, 36, 30, 0.55)
  );
}

.actions-main .btn-tenhou {
  width: 100%;
  padding: 0.95rem 1.25rem;
  font-size: 1.08rem;
  letter-spacing: 0.04em;
  border-radius: 12px;
}

.actions-secondary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.actions-secondary .btn-ghost {
  font-size: 0.82rem;
  padding: 0.5rem 0.85rem;
}

button {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.95rem;
  border-radius: 999px;
  padding: 0.7rem 1.2rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

button:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.btn-ghost:hover {
  border-color: rgba(242, 235, 224, 0.35);
}

.side {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem 1.1rem 1.2rem;
  position: sticky;
  top: 1rem;
  animation: rise 0.8s ease both;
  animation-delay: 0.12s;
}

.side h2 {
  margin: 0 0 0.65rem;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.warnings {
  margin: 0 0 0.75rem;
  padding: 0.55rem 0.7rem;
  list-style: none;
  background: rgba(255, 143, 122, 0.12);
  border: 1px solid rgba(255, 143, 122, 0.35);
  border-radius: 8px;
  color: var(--danger);
  font-size: 0.82rem;
}

.warnings li + li {
  margin-top: 0.25rem;
}

.preview {
  margin: 0;
  max-height: min(52vh, 480px);
  overflow: auto;
  padding: 0.75rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.4);
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-all;
  color: #d7e0d8;
}

.foot {
  margin: 0.75rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* —— 盤面 —— */
.board-block {
  padding-bottom: 1rem;
}

.board-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.board-head h2 {
  margin: 0;
}

.board-toast {
  margin: 0;
  font-size: 0.82rem;
  color: var(--accent);
  max-width: 36rem;
}

.board-legend {
  margin: 0.75rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.75rem;
  align-items: center;
}

.legend-swatch {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  font-size: 0.75rem;
}

.legend-swatch::before {
  content: "";
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 3px;
  border: 2px solid currentColor;
  box-sizing: border-box;
}

.legend-swatch.seat-jicha { color: var(--seat-jicha); }
.legend-swatch.seat-shimocha { color: var(--seat-shimocha); }
.legend-swatch.seat-toimen { color: var(--seat-toimen); }
.legend-swatch.seat-kamicha { color: var(--seat-kamicha); }

.mahjong-board {
  width: 100%;
}

.board-felt {
  position: relative;
  width: min(100%, 720px);
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 18px;
  overflow: visible;
  --tile-sm-w: 1.15rem;
  --tile-sm-h: 1.52rem;
  --tile-md-w: 1.55rem;
  --tile-md-h: 2.05rem;
  /* 中央正方形の半辺（点数・河の共通基準） */
  --board-center-half: min(23%, 115px);
  --board-ring-gap: 0.35rem;
  /* 河: 通常牌6枚分の基準幅（左端固定・リーチで右へ伸びる） */
  --kawa-gap: 0.1rem;
  --kawa-std-w: calc(6 * var(--tile-sm-w) + 5 * var(--kawa-gap));
  background:
    radial-gradient(ellipse 70% 70% at 50% 50%, #2a7a5c 0%, #1a523f 42%, #0d2f26 78%, #071a16 100%);
  box-shadow:
    inset 0 0 0 2px rgba(226, 184, 87, 0.18),
    inset 0 0 60px rgba(0, 0, 0, 0.35),
    0 18px 40px rgba(0, 0, 0, 0.45);
  animation: board-in 0.85s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes board-in {
  from {
    opacity: 0;
    transform: scale(0.97) translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.board-center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(46%, 230px);
  aspect-ratio: 1;
  border-radius: 10px;
  background: linear-gradient(160deg, rgba(8, 36, 28, 0.92), rgba(6, 24, 20, 0.96));
  border: 1px solid rgba(226, 184, 87, 0.22);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  z-index: 2;
}

.board-center-core {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  width: 62%;
  pointer-events: none;
}

.board-center-core .board-dora,
.board-center-core .board-meta {
  pointer-events: auto;
}

.board-meta {
  text-align: center;
  cursor: pointer;
  border-radius: 8px;
  padding: 0.15rem 0.35rem;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.board-meta:hover {
  background: rgba(226, 184, 87, 0.1);
  box-shadow: 0 0 0 1px rgba(226, 184, 87, 0.35);
}

.board-dora {
  display: flex;
  justify-content: center;
  gap: 0.2rem;
  cursor: pointer;
  min-height: 1.4rem;
  border-radius: 6px;
  padding: 0.15rem;
  outline: none;
}

.board-dora.is-focus {
  box-shadow: 0 0 0 2.5px rgba(226, 184, 87, 0.75);
  animation: slot-pulse 1.2s ease infinite;
}

.board-dora .mj-tile.is-focus .mj-face {
  border-color: var(--accent);
  box-shadow: 0 0 0 2.5px rgba(226, 184, 87, 0.75);
  animation: slot-pulse 1.2s ease infinite;
}

.board-round {
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
}

.board-honba {
  font-size: 0.75rem;
  color: var(--muted);
}

/* —— 点数・河: 下辺レイアウトを卓中心で 90° 回転（点対称） —— */
.seat-arm {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  transform-origin: center center;
}

.seat-arm > * {
  pointer-events: auto;
}

.seat-arm[data-rot="0"] {
  transform: rotate(0deg);
}

.seat-arm[data-rot="90"] {
  transform: rotate(90deg);
}

.seat-arm[data-rot="180"] {
  transform: rotate(180deg);
}

.seat-arm[data-rot="-90"] {
  transform: rotate(-90deg);
}

.board-score {
  position: absolute;
  left: 50%;
  top: calc(50% + var(--board-center-half) - var(--board-ring-gap));
  transform: translate(-50%, -100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.05rem;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  font-size: 0.72rem;
  line-height: 1.15;
  white-space: nowrap;
}

.board-score.is-self {
  background: rgba(78, 161, 255, 0.32);
  outline: 1px solid rgba(78, 161, 255, 0.5);
}

.board-score .w {
  font-weight: 800;
  color: var(--accent);
  font-size: 0.85rem;
}

.board-score .pts {
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: -0.02em;
}

.board-kawa-dock {
  position: absolute;
  left: 50%;
  top: calc(50% + var(--board-center-half) + var(--board-ring-gap));
  /* 中央寄せではなく、通常6枚枠の左端を固定（リーチで幅が増えても左がずれない） */
  transform: translateX(calc(var(--kawa-std-w) / -2));
  pointer-events: none;
  z-index: 2;
}

.board-kawa-dock .board-kawa,
.board-kawa-dock .mj-tile,
.board-kawa-dock .board-kawa-slot {
  pointer-events: auto;
}

.board-kawa {
  display: grid;
  grid-template-columns: repeat(6, max-content);
  gap: var(--kawa-gap);
  align-items: center;
  justify-items: start;
  justify-content: start;
  width: max-content;
  min-width: var(--kawa-std-w);
  overflow: visible;
}

.board-kawa-slot {
  --tile-w: var(--tile-sm-w);
  --tile-h: var(--tile-sm-h);
  width: var(--tile-w);
  height: var(--tile-h);
  padding: 0;
  border-radius: 3px;
  border: 1.5px dashed rgba(242, 235, 224, 0.4);
  background: rgba(0, 0, 0, 0.12);
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.board-kawa-slot:hover {
  border-color: var(--accent);
  background: rgba(226, 184, 87, 0.1);
}

.board-kawa-slot.is-focus,
.mj-tile.is-kawa-tile.is-focus .mj-face {
  border-color: var(--accent);
  box-shadow: 0 0 0 2.5px rgba(226, 184, 87, 0.75);
  animation: slot-pulse 1.2s ease infinite;
}

.mj-tile.is-kawa-tile {
  cursor: pointer;
}

@keyframes slot-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 2px rgba(226, 184, 87, 0.45);
  }
  50% {
    box-shadow: 0 0 0 3px rgba(226, 184, 87, 0.85);
  }
}

.kawa-tile-menu {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.kawa-menu-flags {
  margin-bottom: 0.15rem;
}

.kawa-menu-btn {
  width: 100%;
  border-radius: 8px !important;
  justify-content: center;
}

.mj-tile.is-disabled {
  opacity: 0.28;
  cursor: not-allowed;
  filter: grayscale(0.5);
  pointer-events: none;
}

.board-zone {
  position: absolute;
  z-index: 1;
  display: flex;
  pointer-events: none;
}

.board-zone .board-seat,
.board-zone button,
.board-zone .mj-tile {
  pointer-events: auto;
}

.board-seat {
  display: flex;
  align-items: center;
  gap: 0.28rem;
}

.board-hand-wrap {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.2rem;
}

.board-hand,
.board-furos {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.1rem;
  align-items: center;
  justify-content: center;
}

.board-tsumo {
  display: inline-flex;
  margin-left: 0.55rem;
  padding-left: 0.15rem;
}

.hand-edit-row .mj-tile.is-tsumo-preview {
  margin-left: 0.55rem;
}

.board-furo-group {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.06rem;
  padding: 0.08rem;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.2);
}

.board-furo-group.is-raw {
  font-size: 0.55rem;
  font-family: var(--mono);
  color: var(--muted);
  padding: 0.2rem;
}

/* —— 下家（自家）: 下辺に横一列、牌は正立 —— */
.zone-bottom {
  bottom: 1.5%;
  left: 50%;
  transform: translateX(-50%);
  justify-content: center;
}

.zone-bottom .board-seat {
  flex-direction: column;
}

.zone-bottom .board-hand-wrap {
  flex-direction: row; /* 手牌 → 副露 → 鳴き+（右端） */
}

/* —— 対面: 上辺に横一列、牌は 180° —— */
.zone-top {
  top: 1.5%;
  left: 50%;
  transform: translateX(-50%);
  justify-content: center;
}

.zone-top .board-seat {
  flex-direction: column;
}

.zone-top .board-hand-wrap {
  flex-direction: row-reverse; /* プレイヤー右端＝画面左 */
}

.zone-top .mj-tile .mj-face,
.zone-top .mj-tile .mj-back,
.zone-top .board-add-slot,
.zone-top .board-add-furo {
  transform: rotate(180deg);
}

/* —— 上家: 左辺に沿って横並び（画面上は縦列）、牌は -90° —— */
.zone-left {
  left: 1.2%;
  top: 50%;
  transform: translateY(-50%);
  align-items: center;
}

.zone-left .board-seat {
  flex-direction: row;
  align-items: center;
}

.zone-left .board-hand-wrap {
  flex-direction: column; /* 手牌→副露→鳴き+（プレイヤー右＝下） */
}

.zone-left .board-hand,
.zone-left .board-furos,
.zone-left .board-furo-group {
  flex-direction: column;
}

.zone-left .mj-tile {
  width: var(--tile-h);
  height: var(--tile-w);
}

.zone-left .mj-tile .mj-face,
.zone-left .mj-tile .mj-back {
  position: absolute;
  inset: 50% auto auto 50%;
  width: var(--tile-w);
  height: var(--tile-h);
  transform: translate(-50%, -50%) rotate(-90deg);
}

.zone-left .board-add-slot,
.zone-left .board-add-furo {
  width: var(--tile-h);
  height: var(--tile-w);
}

/* —— 下家: 右辺に沿って横並び、牌は +90° —— */
.zone-right {
  right: 1.2%;
  top: 50%;
  transform: translateY(-50%);
  align-items: center;
}

.zone-right .board-seat {
  flex-direction: row;
  align-items: center;
}

.zone-right .board-hand-wrap {
  flex-direction: column-reverse; /* 鳴き+がプレイヤー右＝上 */
}

.zone-right .board-hand,
.zone-right .board-furos,
.zone-right .board-furo-group {
  flex-direction: column;
}

.zone-right .mj-tile {
  width: var(--tile-h);
  height: var(--tile-w);
}

.zone-right .mj-tile .mj-face,
.zone-right .mj-tile .mj-back {
  position: absolute;
  inset: 50% auto auto 50%;
  width: var(--tile-w);
  height: var(--tile-h);
  transform: translate(-50%, -50%) rotate(90deg);
}

.zone-right .board-add-slot,
.zone-right .board-add-furo {
  width: var(--tile-h);
  height: var(--tile-w);
}

.board-add-slot,
.board-add-furo {
  --tile-w: var(--tile-md-w);
  --tile-h: var(--tile-md-h);
  width: var(--tile-w);
  height: var(--tile-h);
  padding: 0;
  border-radius: 4px;
  border: 1.5px dashed rgba(242, 235, 224, 0.35);
  background: rgba(0, 0, 0, 0.15);
  color: var(--muted);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.board-add-slot.size-sm,
.board-add-furo {
  --tile-w: var(--tile-sm-w);
  --tile-h: var(--tile-sm-h);
  font-size: 0.85rem;
}

.board-add-slot.size-md {
  --tile-w: var(--tile-md-w);
  --tile-h: var(--tile-md-h);
}

.board-add-slot:hover,
.board-add-furo:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(226, 184, 87, 0.1);
}

.board-add-slot.dashed {
  border-style: dashed;
}

.board-add-furo {
  border-radius: 6px;
  border-color: rgba(226, 184, 87, 0.4);
  color: var(--accent);
}

/* 牌 */
.mj-tile {
  --tile-w: var(--tile-md-w, 1.55rem);
  --tile-h: var(--tile-md-h, 2.05rem);
  width: var(--tile-w);
  height: var(--tile-h);
  padding: 0;
  border: none;
  border-radius: 3px;
  background: transparent;
  cursor: default;
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.mj-tile.size-sm {
  --tile-w: var(--tile-sm-w, 1.15rem);
  --tile-h: var(--tile-sm-h, 1.52rem);
}

.mj-tile.size-md {
  --tile-w: var(--tile-md-w, 1.55rem);
  --tile-h: var(--tile-md-h, 2.05rem);
}

.mj-face {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 3px;
  object-fit: fill;
  background: #f7f3ea;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.mj-back {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 3px;
  /* assets/tiles/0z.png から抽出（画像は読み込まない） */
  background: #ffc256;
  border: 1px solid rgba(120, 72, 16, 0.45);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

/* ツモ切り: PNG でも分かるよう牌面を薄く（親 opacity だけだと白地が目立つ） */
.mj-tile.is-tsumogiri .mj-face,
.mj-tile.is-tsumogiri .mj-back {
  opacity: 0.4;
  filter: brightness(1.08) saturate(0.75);
}

/* リーチ宣言牌: 横倒し分の幅をレイアウトにも確保（隣牌と重ねない） */
.mj-tile.is-riichi {
  width: var(--tile-h);
  height: var(--tile-w);
  overflow: visible;
  z-index: 1;
}

.mj-tile.is-riichi .mj-face,
.mj-tile.is-riichi .mj-back {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--tile-w);
  height: var(--tile-h);
  max-width: none;
  max-height: none;
  transform: translate(-50%, -50%) rotate(90deg);
  transform-origin: center center;
}

.mj-tile.is-called .mj-face {
  box-shadow: 0 0 0 2.5px var(--call-color, var(--accent));
  outline: 1px solid rgba(0, 0, 0, 0.25);
}

/* 記法パネル */
.notation-details {
  padding-top: 0.65rem;
}

.notation-details > summary {
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  list-style: none;
  margin-bottom: 0.5rem;
}

.notation-details > summary::-webkit-details-marker {
  display: none;
}

.notation-details > summary::before {
  content: "▸ ";
  color: var(--accent);
}

.notation-details[open] > summary::before {
  content: "▾ ";
}

.notation-inner h3 {
  margin: 1rem 0 0.55rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.notation-inner h3:first-child {
  margin-top: 0.25rem;
}

/* モーダル（右側に寄せて盤面を隠さない） */
.board-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 1rem;
  padding-right: max(1rem, env(safe-area-inset-right, 0px));
  background: linear-gradient(
    90deg,
    rgba(4, 14, 12, 0.25) 0%,
    rgba(4, 14, 12, 0.45) 45%,
    rgba(4, 14, 12, 0.72) 100%
  );
  backdrop-filter: none;
  animation: fade-in 0.2s ease both;
}

.board-modal[hidden] {
  display: none !important;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.board-modal-panel {
  width: min(100%, 380px);
  max-height: min(88vh, 640px);
  overflow: auto;
  border-radius: 14px;
  background: linear-gradient(165deg, #1a332c, #10241e);
  border: 1px solid var(--line);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
  animation: slide-in-right 0.3s ease both;
}

@keyframes slide-in-right {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.board-modal-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem 0.4rem;
}

.board-modal-panel header h3 {
  margin: 0;
  font-size: 1rem;
}

.modal-x {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-size: 1.25rem;
  line-height: 1;
}

.board-modal-body {
  padding: 0.4rem 1rem 0.75rem;
}

.round-settings-modal h3 {
  margin: 0.75rem 0 0.4rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.round-settings-modal h3:first-child {
  margin-top: 0.15rem;
}

.round-settings-modal .grid {
  gap: 0.55rem 0.65rem;
}

.grid-situation {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.55rem 0.65rem;
}

.grid-situation .sit-length {
  grid-column: 1;
  grid-row: 1;
}

.grid-situation .sit-dora {
  grid-column: 2 / span 2;
  grid-row: 1;
}

.grid-situation .sit-bakaze {
  grid-column: 1;
  grid-row: 2;
}

.grid-situation .sit-kyoku {
  grid-column: 2;
  grid-row: 2;
}

.grid-situation .sit-honba {
  grid-column: 3;
  grid-row: 2;
}

.grid-situation .sit-kyoutaku {
  grid-column: 1;
  grid-row: 3;
}

.grid-situation .sit-jikaze {
  grid-column: 2;
  grid-row: 3;
}

.score-editor {
  margin-top: 0.35rem;
}

.score-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.score-editor-head h3 {
  margin: 0;
}

.btn-score-reset {
  margin: 0;
  padding: 0.28rem 0.65rem;
  font-size: 0.72rem;
}

.score-seat-map {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto auto auto;
  gap: 0.55rem 0.35rem;
  align-items: center;
  justify-items: center;
  padding: 0.35rem 0 0.15rem;
}

.score-toimen {
  grid-column: 2;
  grid-row: 1;
}

.score-kamicha {
  grid-column: 1;
  grid-row: 2;
  justify-self: start;
}

.score-total {
  grid-column: 2;
  grid-row: 2;
  justify-self: center;
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.score-shimocha {
  grid-column: 3;
  grid-row: 2;
  justify-self: end;
}

.score-jicha {
  grid-column: 2;
  grid-row: 3;
}

.score-cell {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.score-lab {
  font-weight: 700;
  min-width: 2em;
}

.score-input-wrap {
  display: inline-flex;
  align-items: baseline;
  gap: 0.12rem;
}

.score-input-wrap input {
  width: 3.6rem;
  margin: 0;
  padding: 0.35rem 0.4rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.score-suffix {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
  opacity: 0.85;
}

.board-modal-panel footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.5rem 1rem 1rem;
}

.furo-dialog {
  display: grid;
  gap: 0.65rem;
}

.furo-dialog label {
  font-size: 0.78rem;
  color: var(--muted);
}

label.board-check,
.board-check {
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  writing-mode: horizontal-tb;
  cursor: pointer;
}

.board-check input {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.tile-picker .picker-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.65rem;
  flex-wrap: wrap;
}

.picker-tabs button {
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
}

.picker-tabs button.is-on {
  background: rgba(226, 184, 87, 0.2);
  border-color: var(--accent);
  color: var(--accent);
}

.picker-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.picker-grid .mj-tile {
  cursor: pointer;
}

.hand-edit-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 0.35rem 0 0.15rem;
  min-height: 2.2rem;
}

.hand-edit-row .mj-tile {
  cursor: pointer;
}

.discard-pick-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0.5rem 0;
  max-height: 280px;
  overflow: auto;
}

.discard-pick-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  color: var(--ink);
  text-align: left;
  font-size: 0.85rem;
}

.discard-pick-item:hover {
  border-color: var(--accent);
  background: rgba(226, 184, 87, 0.08);
}

/* 右側固定・牌一覧シート（内容高さ。全画面は不要） */
.tile-sheet {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  pointer-events: none;
  padding: 0.75rem 0.75rem 0.75rem 0;
  padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
  animation: sheet-in-right 0.28s ease both;
}

.tile-sheet[hidden] {
  display: none !important;
}

@keyframes sheet-in-right {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.tile-sheet-panel {
  pointer-events: auto;
  width: min(100vw - 1.5rem, 360px);
  height: auto;
  max-height: calc(100vh - 1.5rem);
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  background: linear-gradient(180deg, #1e3d34 0%, #122820 100%);
  border: 1px solid rgba(226, 184, 87, 0.28);
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.tile-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.85rem 0.55rem;
  flex-shrink: 0;
}

.tile-sheet-head h3 {
  margin: 0 0 0.15rem;
  font-size: 0.95rem;
}

.tile-sheet-extra {
  padding: 0.2rem 0 0.15rem;
  flex-shrink: 0;
}

.tile-sheet-flags {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem;
}

.tile-sheet-section {
  flex-shrink: 0;
  padding: 0.2rem 0.85rem 0.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.tile-sheet-section-title {
  flex: none;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.tile-sheet-keys {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

.tile-sheet-keys-line {
  margin: 0.1rem 0;
}

.tile-sheet-keys-example {
  margin-bottom: 0.55rem;
}

.tile-sheet-keys kbd {
  display: inline-block;
  min-width: 1.15em;
  padding: 0.08em 0.32em;
  margin: 0 0.08em;
  border-radius: 4px;
  border: 1px solid rgba(226, 184, 87, 0.35);
  background: rgba(0, 0, 0, 0.35);
  font-family: var(--mono);
  font-size: 0.9em;
  color: var(--accent);
  text-align: center;
}

.tile-sheet-keys-buf {
  margin: 0.25rem 0 0;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.85rem;
}

.mj-tile.is-dora-tile {
  cursor: pointer;
}

.tile-sheet-grid {
  flex: 0 1 auto;
  overflow: auto;
  padding: 0.1rem 0 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-height: 0;
}

.tile-sheet-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  width: 100%;
  box-sizing: border-box;
  padding: 0.2rem 0.25rem;
  border-radius: 8px;
  border: 1.5px solid transparent;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}

.tile-sheet-row.is-key-focus {
  border-color: var(--accent);
  background: rgba(226, 184, 87, 0.08);
}

.tile-sheet-suit {
  flex: none;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.tile-sheet-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
  width: 100%;
}

.tile-sheet-tiles .mj-tile.is-pickable,
.hand-edit-row .mj-tile.is-pickable {
  cursor: pointer;
}

.tile-sheet-tiles .mj-tile.is-pickable:hover {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* 編集アクション: 牌一覧の直下（閉じるとは別帯） */
.tile-sheet-actions {
  flex-shrink: 0;
  padding: 0.55rem 0.75rem;
  border-top: 1px solid rgba(226, 184, 87, 0.18);
  background: rgba(0, 0, 0, 0.18);
}

.tile-sheet-edit-stack {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: 100%;
}

.tile-sheet-edit-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  width: 100%;
}

.tile-sheet-edit-nav:has(> :only-child) {
  grid-template-columns: 1fr;
}

.tile-sheet-edit-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.4rem;
  width: 100%;
}

.tile-sheet-action-btn {
  display: inline-flex !important;
  flex-direction: row !important;
  align-items: center;
  justify-content: center;
  gap: 0.28rem;
  width: 100%;
  margin: 0;
  padding: 0.45rem 0.3rem;
  font-size: 0.76rem;
  border-radius: 8px;
  white-space: nowrap;
}

.tile-sheet-action-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.ui-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 0;
}

.ui-icon-svg,
.ui-icon svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
}

.tile-sheet-foot {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem 0.6rem;
  flex-shrink: 0;
  border-top: 1px solid rgba(226, 184, 87, 0.12);
}

.tile-sheet-close {
  border-radius: 8px !important;
  padding: 0.4rem 0.9rem;
  font-size: 0.82rem;
}

body.tile-sheet-open .shell {
  padding-right: min(380px, 42vw);
}

@media (max-width: 720px) {
  body.tile-sheet-open .shell {
    padding-right: 0;
    padding-bottom: min(50vh, 360px);
  }

  .tile-sheet {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0 0.5rem calc(0.5rem + env(safe-area-inset-bottom, 0px));
    animation: sheet-up 0.28s ease both;
  }

  @keyframes sheet-up {
    from {
      opacity: 0;
      transform: translateY(24px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }

  .tile-sheet-panel {
    width: 100%;
    max-height: min(58vh, 420px);
    height: auto;
    border-radius: 14px 14px 10px 10px;
  }

  .board-modal {
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 0.75rem;
  }

  .board-modal-panel {
    width: min(100%, 420px);
  }
}

@media (max-width: 640px) {
  .board-felt {
    width: 100%;
    aspect-ratio: 0.92;
    --tile-sm-w: 0.95rem;
    --tile-sm-h: 1.28rem;
  }

  .board-center {
    width: min(48%, 170px);
    padding: 0.4rem;
  }

  .tile-sheet-section-title {
    font-size: 0.8rem;
  }

  .tile-sheet-suit {
    font-size: 0.65rem;
  }
}
