/* =============================================================
 * style.css — スマートフォン特化 UI
 * ============================================================= */

:root {
  color-scheme: dark;
  --bg: #090907;
  --bg-soft: #13120f;
  --panel: rgba(27, 25, 21, 0.96);
  --panel-2: #211e19;
  --line: #453e34;
  --line-soft: rgba(224, 199, 158, 0.13);
  --text: #f5efe5;
  --text-dim: #aea496;
  --accent: #e1ad50;
  --accent-2: #b97524;
  --accent-soft: rgba(225, 173, 80, 0.15);
  --danger: #e36d62;
  --ok: #68c78a;
  --info: #79abd1;
  --scrollbar-track: rgba(8, 7, 6, 0.58);
  --scrollbar-thumb: #8e6838;
  --scrollbar-thumb-highlight: #c3934e;
  --scrollbar-thumb-active: #e2b75f;

  --board-bg: #aa672f;
  --board-bg-2: #754118;
  --board-line: #2d190b;
  --board-rim: #321a0a;
  --board-rim-light: rgba(240, 177, 94, 0.5);
  --board-texture: url('assets/kaya-wood-real-v2.jpg');
  --board-wash:
    radial-gradient(120% 90% at 42% 3%, rgba(255, 211, 142, 0.2), transparent 52%),
    linear-gradient(104deg, rgba(108, 47, 11, 0.08), rgba(248, 181, 91, 0.16) 48%, rgba(62, 27, 8, 0.15));
  --koma-face: #f4dfb7;
  --koma-face-2: #d5ae70;
  --koma-edge: #8c572b;
  --koma-edge-dark: #4a260f;
  --koma-text: #160d06;
  --koma-texture: url('assets/koma-wood-real-v2.jpg');

  --radius: 12px;
  --radius-sm: 9px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --tap: 46px;

  /* スマホと同一サイズで表示するための論理画面サイズ */
  --frame-w: 390px;
  --frame-h: 844px;
}

[data-board-theme='kaya'] {
  --board-bg: #a7622b;
  --board-bg-2: #7b431b;
  --board-line: #2b180a;
  --board-wash: linear-gradient(155deg, rgba(244, 187, 107, 0.29), rgba(74, 31, 8, 0.12));
}
[data-board-theme='sakura'] {
  --board-bg: #c88f83;
  --board-bg-2: #a8655d;
  --board-line: #58332f;
  --board-rim: #4a2a27;
  --board-rim-light: rgba(236, 177, 164, 0.45);
  --koma-face: #fff5ec;
  --koma-face-2: #e8ceb9;
  --koma-edge: #8d5844;
  --koma-edge-dark: #573126;
  --board-texture: none;
  --board-wash: linear-gradient(160deg, var(--board-bg), var(--board-bg-2));
}
[data-board-theme='night'] {
  --board-bg: #3e4a56;
  --board-bg-2: #35404a;
  --board-line: #94a7b8;
  --koma-face: #dfe7ee;
  --koma-face-2: #c3ceda;
  --koma-edge: #7d8fa0;
  --koma-edge-dark: #4d5b68;
  --koma-text: #16202a;
  --board-rim: #1f2932;
  --board-rim-light: rgba(178, 198, 214, 0.42);
  --board-texture: none;
  --board-wash: linear-gradient(160deg, var(--board-bg), var(--board-bg-2));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  width: 100%;
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(82, 60, 33, 0.18), transparent 58%),
    linear-gradient(rgba(9, 9, 7, 0.78), rgba(9, 9, 7, 0.78)),
    url('assets/washi-dark.jpg');
  background-size: auto, auto, 520px 520px;
  color: var(--text);
  font-family: 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Yu Gothic', 'Noto Sans JP', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

html[lang='ar'] body {
  font-family: 'Segoe UI', Tahoma, Arial, 'Noto Sans Arabic', sans-serif;
}

html:is([lang='ko'], [lang^='zh']) body {
  font-family: 'Noto Sans CJK KR', 'Noto Sans CJK SC', 'Noto Sans CJK TC',
    'Malgun Gothic', 'Microsoft YaHei UI', 'Microsoft JhengHei UI', sans-serif;
}

html:is([lang='hi'], [lang='bn'], [lang='th']) body {
  font-family: 'Noto Sans Devanagari', 'Noto Sans Bengali', 'Noto Sans Thai',
    'Nirmala UI', 'Leelawadee UI', sans-serif;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
  font-family: inherit;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

.icon {
  width: 1.25em;
  height: 1.25em;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

:focus-visible {
  outline: 2px solid #f3ca75;
  outline-offset: 2px;
}

/* ---------- 端末枠（スマホ実寸） ---------- */

#device {
  --app-w: 100vw;
  --app-h: 100dvh;
  position: relative;
  width: var(--app-w);
  height: var(--app-h);
  overflow: hidden;
  background-color: var(--bg);
  background-image:
    radial-gradient(110% 58% at 50% 44%, rgba(72, 49, 24, 0.12), transparent 72%),
    linear-gradient(rgba(9, 9, 7, 0.74), rgba(9, 9, 7, 0.74)),
    url('assets/washi-dark.jpg');
  background-size: auto, auto, 460px 460px;
}

#app {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

/* PC（マウス操作の広い画面）ではスマホと同じ論理サイズの枠に固定して中央に表示する。
   タッチ端末は横向きでも常に全画面のまま。 */
@media (min-width: 501px) and (hover: hover) and (pointer: fine) {
  body {
    display: flex;
    align-items: center;
    justify-content: center;
    background:
      radial-gradient(120% 90% at 50% 0%, #1c1712 0%, #0a0908 55%, #050505 100%);
  }
  #device {
    --app-w: var(--frame-w);
    --app-h: var(--frame-h);
    flex: none;
    border-radius: 40px;
    /* ベゼルは border ではなく box-shadow で描く。
       border だと内側の描画領域が実機より小さくなってしまうため。 */
    box-shadow:
      0 0 0 8px #11100d,
      0 0 0 9px #4b4439,
      0 34px 78px rgba(0, 0, 0, 0.78),
      0 5px 16px rgba(0, 0, 0, 0.66),
      inset 0 1px rgba(255, 255, 255, 0.02);
    transform: scale(var(--frame-scale, 1));
    transform-origin: center center;
  }
}

/* ---------- 画面遷移 ---------- */

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + 12px) calc(var(--safe-bottom) + 8px) calc(var(--safe-left) + 12px);
  overflow: hidden;
}
.screen.active {
  display: flex;
  animation: screen-enter 0.22s cubic-bezier(.2, .76, .22, 1);
}
@keyframes screen-enter {
  from { opacity: 0; transform: translateY(7px) scale(.995); }
  to { opacity: 1; transform: translateY(0); }
}
.screen-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 24px;
}

/* ---------- スクロールバー ----------
   和紙の暗部を溝、木と真鍮の中間色をつまみにして全スクロール面を統一する。
   駒台の横スクロールは操作の邪魔にならないよう、従来どおり非表示。 */
:is(.screen-scroll, .sheet, .kifu-list, .chat-log, .history-kifu-text) {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
  overscroll-behavior-y: contain;
}

:is(.screen-scroll, .sheet, .kifu-list, .chat-log, .history-kifu-text)::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

:is(.screen-scroll, .sheet, .kifu-list, .chat-log, .history-kifu-text)::-webkit-scrollbar-button {
  width: 0;
  height: 0;
  display: none;
  border: 0;
  background: transparent;
  -webkit-appearance: none;
}

:is(.screen-scroll, .sheet, .kifu-list, .chat-log, .history-kifu-text)::-webkit-scrollbar-button:vertical:start:decrement,
:is(.screen-scroll, .sheet, .kifu-list, .chat-log, .history-kifu-text)::-webkit-scrollbar-button:vertical:end:increment {
  width: 0;
  height: 0;
  display: none;
  background: transparent;
}

:is(.screen-scroll, .sheet, .kifu-list, .chat-log, .history-kifu-text)::-webkit-scrollbar-track {
  background:
    linear-gradient(
      90deg,
      transparent 0 2px,
      var(--scrollbar-track) 2px 6px,
      transparent 6px
    );
  border-radius: 999px;
}

:is(.screen-scroll, .sheet, .kifu-list, .chat-log, .history-kifu-text)::-webkit-scrollbar-thumb {
  min-height: 38px;
  border: 2px solid transparent;
  border-radius: 999px;
  background:
    linear-gradient(180deg, var(--scrollbar-thumb-highlight), var(--scrollbar-thumb))
    padding-box;
  box-shadow:
    inset 0 1px rgba(255, 230, 174, 0.26),
    inset 0 -1px rgba(43, 23, 9, 0.36);
}

:is(.screen-scroll, .sheet, .kifu-list, .chat-log, .history-kifu-text)::-webkit-scrollbar-thumb:hover {
  background:
    linear-gradient(180deg, #d3a65c, #a3763e)
    padding-box;
}

:is(.screen-scroll, .sheet, .kifu-list, .chat-log, .history-kifu-text)::-webkit-scrollbar-thumb:active {
  background: var(--scrollbar-thumb-active) padding-box;
}

:is(.screen-scroll, .sheet, .kifu-list, .chat-log, .history-kifu-text)::-webkit-scrollbar-corner {
  background: transparent;
}

/* ---------- 共通パーツ ---------- */

.title-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line-soft);
}
.title-bar h2 {
  margin: 0;
  font-family: 'Yu Mincho', 'Hiragino Mincho ProN', 'Noto Serif JP', serif;
  font-size: 1.08rem;
  letter-spacing: 0.08em;
  flex: 1;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: linear-gradient(155deg, #29251f, #1c1a16);
  color: var(--text);
  border-radius: var(--radius-sm);
  min-height: var(--tap);
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.035),
    0 2px 4px rgba(0, 0, 0, 0.18);
  transition:
    transform 0.11s cubic-bezier(.2, .8, .2, 1),
    filter 0.16s ease,
    border-color 0.16s ease,
    box-shadow 0.16s ease;
  cursor: pointer;
}
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) {
    border-color: #756653;
    box-shadow:
      inset 0 1px rgba(255, 255, 255, 0.045),
      0 4px 10px rgba(0, 0, 0, 0.24);
  }
}
.btn:active {
  transform: translateY(1px) scale(.985);
  filter: brightness(1.1);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.25);
}
.btn:disabled {
  opacity: 0.36;
  cursor: not-allowed;
  filter: grayscale(0.35);
}
.btn.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-color: #8c5f21;
  color: #241703;
  box-shadow:
    inset 0 1px rgba(255, 245, 205, 0.45),
    0 4px 12px rgba(95, 54, 10, 0.24);
}
.btn.danger { background: #46231f; border-color: #7c3a32; color: #ffd7d2; }
.btn.ghost { background: transparent; }
.btn.icon {
  min-width: var(--tap);
  padding: 8px;
  font-size: 1.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn.block { width: 100%; }
.btn.with-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.card {
  background: linear-gradient(145deg, rgba(38, 34, 29, 0.97), rgba(23, 22, 18, 0.97));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.025),
    0 8px 20px rgba(0, 0, 0, 0.12);
}
.card h3 {
  margin: 0 0 10px;
  font-size: 0.82rem;
  letter-spacing: 0.14em;
  color: #e6bf70;
  font-weight: 700;
}

.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field > label {
  display: block;
  font-size: 0.76rem;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  margin-bottom: 6px;
}

.control {
  width: 100%;
  min-height: var(--tap);
  background: rgba(17, 16, 14, 0.88);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 1rem;
}
select.control {
  appearance: none;
  color-scheme: dark;
  color: #f4eee4;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%), linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

/*
 * 展開後の選択肢は OS のネイティブ UI で描画されるため、select 本体の
 * 配色だけでは Windows/Chromium で白背景・白文字になることがある。
 * 各状態の前景色と背景色を明示し、どの言語でも十分なコントラストを保つ。
 */
select.control option,
select.control optgroup {
  color: #f4eee4;
  background-color: #17140f;
}

select.control option:checked {
  color: #170f05;
  background-color: #d6a550;
}

select.control option:disabled {
  color: #8f8679;
  background-color: #17140f;
}

.seg {
  display: flex;
  gap: 6px;
  background: rgba(17, 16, 14, 0.88);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px;
}
.seg button {
  flex: 1;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  min-height: 40px;
  border-radius: 7px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}
.seg button[aria-pressed='true'] {
  background: var(--accent);
  color: #241703;
}
.language-seg button {
  padding-inline: 4px;
  font-size: 0.82rem;
  letter-spacing: 0;
}

.language-select {
  width: 100%;
  min-height: 46px;
  text-align: start;
}

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.hint {
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.6;
  margin: 6px 0 0;
}
.hint.warn { color: #f0c070; }

/* ---------- ルール解説 ---------- */

#rules-body {
  padding-inline: 1px 4px;
  scroll-padding-block: 12px;
}

.rule-card {
  padding: 0;
  overflow: hidden;
  border-color: rgba(202, 160, 91, 0.34);
  background:
    linear-gradient(145deg, rgba(43, 37, 31, 0.98), rgba(24, 22, 19, 0.98));
  box-shadow:
    0 7px 18px rgba(0, 0, 0, 0.18),
    inset 0 1px rgba(255, 231, 187, 0.035);
}

.rule-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 47px;
  padding: 10px 13px;
  border-bottom: 1px solid rgba(202, 160, 91, 0.24);
  background:
    linear-gradient(90deg, rgba(203, 147, 67, 0.15), rgba(203, 147, 67, 0.025));
}

.rule-number {
  display: inline-flex;
  flex: 0 0 27px;
  width: 27px;
  height: 27px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(226, 183, 95, 0.52);
  border-radius: 50%;
  color: #f0cf8d;
  background: rgba(11, 10, 8, 0.35);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.rule-card .rule-heading h3 {
  margin: 0;
  color: #f0c873;
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  line-height: 1.35;
}

.rule-lead {
  margin: 0;
  padding: 12px 13px;
  color: #d8cfc2;
  border-bottom: 1px solid var(--line-soft);
  font-size: 0.79rem;
  font-weight: 500;
  line-height: 1.72;
}

.rule-list {
  padding: 0 13px 4px;
}

.rule-item {
  padding: 11px 0 10px;
}

.rule-item + .rule-item {
  border-top: 1px solid var(--line-soft);
}

.rule-term {
  margin: 0 0 4px;
  color: #ead8b9;
  font-size: 0.77rem;
  font-weight: 700;
  letter-spacing: 0.035em;
  line-height: 1.5;
}

.rule-term::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 4px;
  margin-inline-end: 7px;
  border-radius: 50%;
  vertical-align: 0.14em;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(226, 183, 95, 0.1);
}

.rule-text {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.75rem;
  line-height: 1.72;
}

html[dir='rtl'] .rule-card .rule-heading h3,
html[dir='rtl'] .rule-term {
  letter-spacing: 0;
}

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--tap);
  gap: 12px;
  position: relative;
  cursor: pointer;
}
.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  opacity: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.switch .track {
  width: 50px;
  height: 30px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  transition: background 0.18s ease;
  flex: none;
}
.switch .track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.18s ease;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.volume-control {
  display: grid;
  gap: 7px;
  padding: 5px 0 10px;
}
.volume-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-dim);
  font-size: 0.82rem;
}
.volume-label output {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}
.volume-control input[type='range'] {
  width: 100%;
  height: 24px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.volume-control input[type='range']::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    var(--accent-2) 0 var(--volume-fill, 72%),
    var(--line) var(--volume-fill, 72%) 100%
  );
}
.volume-control input[type='range']::-webkit-slider-thumb {
  width: 20px;
  height: 20px;
  margin-top: -8px;
  border: 2px solid #fff1c8;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.38);
  -webkit-appearance: none;
}

/* ---------- ホーム ---------- */

.home-hero {
  text-align: center;
  padding: 22px 0 18px;
  position: relative;
}
.home-hero::after {
  content: '';
  display: block;
  width: 36px;
  height: 1px;
  margin: 13px auto 0;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
.home-hero .logo {
  font-family: 'Yu Mincho', 'Hiragino Mincho ProN', 'Noto Serif JP', serif;
  font-size: 3.05rem;
  letter-spacing: 0.3em;
  font-weight: 700;
  margin: 0;
  color: var(--accent);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.48);
  padding-left: 0.3em;
}
.home-hero .sub {
  margin: 6px 0 0;
  font-size: 0.76rem;
  letter-spacing: 0.3em;
  color: var(--text-dim);
}

.menu-grid { display: grid; gap: 10px; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(39, 34, 29, 0.97), rgba(29, 26, 22, 0.97));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 70px;
  cursor: pointer;
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.03),
    0 6px 16px rgba(0, 0, 0, 0.14);
  transition: transform 0.12s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}
@media (hover: hover) and (pointer: fine) {
  .menu-item:hover {
    border-color: #70614d;
    box-shadow:
      inset 3px 0 rgba(225, 173, 80, 0.65),
      0 8px 20px rgba(0, 0, 0, 0.2);
  }
}
.menu-item:active { filter: brightness(1.12); transform: translateY(1px) scale(.99); }
.menu-item .mi-icon {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(226, 183, 95, 0.26);
  border-radius: 10px;
  color: var(--accent);
  background: rgba(226, 183, 95, 0.055);
  display: grid;
  place-items: center;
  flex: none;
}
.menu-item .mi-icon .icon { width: 21px; height: 21px; }
.menu-item .mi-title { font-size: 1.02rem; font-weight: 700; display: block; }
.menu-item .mi-desc { font-size: 0.74rem; color: var(--text-dim); display: block; margin-top: 4px; line-height: 1.4; }

.stat-row { display: flex; gap: 8px; text-align: center; }
.stat-row > div {
  flex: 1;
  background: rgba(15, 14, 12, 0.7);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 4px;
}
.stat-row b { display: block; font-size: 1.35rem; color: var(--accent); }
.stat-row span { font-size: 0.7rem; color: var(--text-dim); letter-spacing: 0.1em; }

/* ---------- 対局画面 ---------- */

#screen-game {
  padding-top: calc(var(--safe-top) + 6px);
  padding-right: calc(var(--safe-right) + 6px);
  padding-bottom: calc(var(--safe-bottom) + 6px);
  padding-left: calc(var(--safe-left) + 6px);
}

.game-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 4px;
}

.player-bar {
  display: flex;
  align-items: center;
  gap: 9px;
  background:
    linear-gradient(118deg, rgba(38, 35, 29, 0.98), rgba(21, 20, 17, 0.98));
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 6px 11px;
  min-height: 46px;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.03),
    0 3px 9px rgba(0, 0, 0, 0.12);
  transition:
    border-color 0.22s ease,
    background-color 0.22s ease,
    box-shadow 0.22s ease;
}
.player-bar::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  opacity: 0;
  background: linear-gradient(105deg, transparent 12%, rgba(255, 222, 155, 0.13) 48%, transparent 78%);
  transform: translateX(-100%);
  pointer-events: none;
}
.player-bar::after {
  content: '';
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 0;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: transparent;
  box-shadow: none;
  transition: background-color .2s ease, box-shadow .2s ease;
}
.player-bar.turn-active {
  border-color: var(--accent);
  background:
    linear-gradient(118deg, rgba(56, 47, 32, 0.98), rgba(25, 23, 19, 0.99));
  box-shadow:
    0 0 0 1px rgba(255, 220, 145, 0.2) inset,
    0 4px 12px rgba(0, 0, 0, 0.2),
    0 0 14px rgba(225, 173, 80, 0.07);
  animation: turn-focus .36s cubic-bezier(.2, .78, .2, 1);
}
.player-bar.turn-active::before {
  opacity: 1;
  animation: turn-sheen .7s cubic-bezier(.2, .7, .2, 1) both;
}
.player-bar.turn-active::after {
  background: var(--accent);
  box-shadow: 0 0 9px rgba(225, 173, 80, 0.72);
}
.player-bar.turn-active .pb-name,
.player-bar.turn-active .pb-clock {
  color: #ffe5a7;
}
@keyframes turn-focus {
  from { transform: scale(.992); filter: brightness(.84); }
  to { transform: scale(1); filter: brightness(1); }
}
@keyframes turn-sheen {
  0% { transform: translateX(-100%); opacity: 0; }
  28% { opacity: 1; }
  100% { transform: translateX(100%); opacity: 0; }
}
.pb-mark {
  width: 24px;
  font-family: 'Yu Mincho', 'Hiragino Mincho ProN', 'Noto Serif JP', serif;
  font-size: 1.08rem;
  color: #dfd5c5;
  text-align: center;
  flex: none;
}
.pb-name {
  font-size: 0.91rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.pb-tag {
  font-size: 0.62rem;
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  flex: none;
}
.pb-clock {
  font-variant-numeric: tabular-nums;
  font-family: 'Yu Mincho', 'Hiragino Mincho ProN', 'Noto Serif JP', serif;
  font-size: 1.13rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  flex: none;
  min-width: 62px;
  text-align: right;
}
.pb-clock.byoyomi { color: var(--accent); }
.pb-clock.danger { color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.52; } }

.hand-tray {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 40px;
  padding: 2px 8px;
  background:
    linear-gradient(120deg, rgba(15, 14, 12, 0.9), rgba(20, 18, 15, 0.76));
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  box-shadow:
    inset 0 1px 5px rgba(0, 0, 0, 0.26),
    0 1px rgba(255, 255, 255, 0.015);
  transition: border-color .2s ease, background-color .2s ease, box-shadow .2s ease;
}
.hand-tray::-webkit-scrollbar { display: none; }
.hand-tray.empty::before {
  content: '◇  ' attr(data-empty-label);
  font-size: 0.72rem;
  color: var(--text-dim);
  padding-inline-start: 4px;
  letter-spacing: 0.03em;
}

html[lang='ar'] .hand-tray.empty::before {
  direction: rtl;
  unicode-bidi: plaintext;
}

/* Arabic UI follows RTL reading order, while the physical board, clocks,
   room codes, and KIF geometry remain fixed in their standard LTR order. */
html[dir='rtl'] .board-area,
html[dir='rtl'] .board-frame,
html[dir='rtl'] .board-grid,
html[dir='rtl'] .coord-files,
html[dir='rtl'] .coord-ranks,
html[dir='rtl'] .hand-tray,
html[dir='rtl'] .pb-clock,
html[dir='rtl'] .kifu-list,
html[dir='rtl'] .code-input,
html[dir='rtl'] .code-value,
html[dir='rtl'] #room-code {
  direction: ltr;
}

html[dir='rtl'] .title-bar h2,
html[dir='rtl'] .card,
html[dir='rtl'] .sheet {
  text-align: right;
}

html[dir='rtl'] select.control {
  background-position: 20px 50%, 14px 50%;
  padding-right: 12px;
  padding-left: 36px;
}

html[dir='rtl'] .player-bar::after {
  left: auto;
  right: 0;
  border-radius: 2px 0 0 2px;
}

html[dir='rtl'] .status-strip .move-text {
  direction: rtl;
  unicode-bidi: plaintext;
  text-align: right;
}

html[dir='rtl'] [data-back] .icon {
  transform: scaleX(-1);
}

html[dir='rtl'] #history-list {
  direction: rtl;
}

html[dir='rtl'] #history-list .history-entry,
html[dir='rtl'] #history-list .mv {
  text-align: right;
  unicode-bidi: plaintext;
}

html[dir='rtl'] #history-list .tm {
  direction: rtl;
  text-align: left;
  unicode-bidi: plaintext;
}

.hand-koma {
  position: relative;
  isolation: isolate;
  flex: none;
  width: 36px;
  height: 39px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.hand-koma .koma { width: 100%; height: 100%; font-size: 19px; }
.hand-koma .count {
  position: absolute;
  right: -3px;
  bottom: -3px;
  z-index: 5;
  background: var(--accent);
  color: #241703;
  font-size: 0.65rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  border-radius: 999px;
  border: 1px solid rgba(54, 31, 6, 0.82);
  min-width: 16px;
  height: 16px;
  line-height: 14px;
  text-align: center;
  padding: 0 3px;
  box-shadow:
    0 1px 0 rgba(255, 232, 173, 0.36) inset,
    0 2px 4px rgba(0, 0, 0, 0.42);
  pointer-events: none;
}
.hand-koma[aria-pressed='true'] .koma {
  transform: translateY(-4px) rotate(var(--piece-rotation)) scale(1.055);
  filter:
    drop-shadow(0 1px 0 rgba(255, 250, 230, 0.86))
    drop-shadow(0 3px 0 var(--koma-edge-dark))
    drop-shadow(0 8px 5px rgba(0, 0, 0, 0.5));
}
.hand-koma.top-side .koma { --piece-rotation: 180deg; }
.hand-koma.bottom-side .koma { --piece-rotation: 0deg; }
.hand-tray.locked .hand-koma { pointer-events: none; opacity: 0.75; }
.hand-tray.received-piece {
  animation: tray-receive 0.48s cubic-bezier(.2, .8, .2, 1);
}
@keyframes tray-receive {
  0% { transform: scaleX(1); }
  30% {
    transform: scaleX(1.01);
    border-color: rgba(231, 184, 91, 0.95);
    box-shadow: inset 0 0 14px rgba(226, 183, 95, 0.2), 0 0 7px rgba(226, 183, 95, 0.1);
  }
  100% { transform: scaleX(1); }
}

/* 盤 */
.board-area {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 12px 8px 2px 0;
  isolation: isolate;
}
.board-area::before {
  content: '';
  position: absolute;
  z-index: -1;
  width: 96%;
  aspect-ratio: 1 / 1.06;
  border-radius: 24px;
  background: radial-gradient(ellipse at 50% 44%, rgba(201, 132, 55, 0.13), transparent 70%);
  filter: blur(13px);
  pointer-events: none;
}

.board-frame {
  position: relative;
  z-index: 1;
  background-color: var(--board-bg);
  background-image:
    var(--board-wash),
    var(--board-texture);
  background-size: cover, cover, 172% auto;
  background-position: center, center, 50% 46%;
  background-blend-mode: normal, normal, normal;
  border: 2px solid var(--board-rim);
  border-radius: 5px;
  box-shadow:
    0 11px 24px rgba(0, 0, 0, 0.62),
    0 0 0 1px var(--board-rim-light),
    0 0 0 4px rgba(30, 15, 6, 0.8),
    0 0 0 5px rgba(222, 142, 64, 0.12),
    inset 0 1px 0 rgba(255, 224, 170, 0.3),
    inset 0 0 26px rgba(45, 18, 4, 0.18);
  padding: 4px;
  touch-action: manipulation;
  transform-origin: 50% 50%;
  will-change: transform, filter, opacity;
}
.board-frame::before {
  content: '';
  position: absolute;
  inset: 1px;
  z-index: 5;
  border: 1px solid rgba(255, 219, 157, 0.17);
  border-radius: 2px;
  box-shadow:
    inset 0 1px rgba(255, 238, 203, 0.18),
    inset 0 -1px rgba(63, 25, 6, 0.38);
  pointer-events: none;
}
.board-frame.piece-in-flight {
  box-shadow:
    0 14px 28px rgba(0, 0, 0, 0.66),
    0 0 0 1px var(--board-rim-light),
    0 0 0 4px rgba(30, 15, 6, 0.82),
    0 0 18px rgba(210, 139, 56, 0.1),
    inset 0 1px 0 rgba(255, 224, 170, 0.3);
}
.board-frame.board-flip-out {
  animation: board-flip-out 0.16s cubic-bezier(.42, 0, .7, 1) forwards;
}
.board-frame.board-flip-in {
  animation: board-flip-in 0.25s cubic-bezier(.18, .75, .2, 1) both;
}
@keyframes board-flip-out {
  to { transform: perspective(760px) rotateY(10deg) scale(.965); filter: brightness(.68) saturate(.82); opacity: .34; }
}
@keyframes board-flip-in {
  from { transform: perspective(760px) rotateY(-10deg) scale(.965); filter: brightness(.7) saturate(.84); opacity: .38; }
  to { transform: perspective(700px) rotateY(0) scale(1); filter: brightness(1); opacity: 1; }
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%;
  height: 100%;
  border: 1px solid var(--board-line);
  box-shadow:
    inset 0 0 7px rgba(31, 13, 4, 0.16),
    0 0 0 1px rgba(255, 222, 169, 0.055);
}

.cell {
  position: relative;
  border: 0;
  border-right: 1px solid var(--board-line);
  border-bottom: 1px solid var(--board-line);
  padding: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow: none;
  transition:
    background-color 0.15s ease,
    box-shadow 0.18s ease,
    filter 0.15s ease;
}
.cell:nth-child(9n) { border-right: 0; }
.cell:nth-last-child(-n + 9) { border-bottom: 0; }

.cell.star::before {
  content: '';
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--board-line);
  z-index: 1;
}

.cell.last-move {
  background: rgba(177, 92, 22, 0.14);
}
.cell.last-from {
  box-shadow: inset 0 0 0 1px rgba(123, 60, 15, 0.3);
}
.cell.last-to {
  background:
    linear-gradient(116deg, rgba(138, 67, 15, 0.19) 0 36%, rgba(255, 211, 122, 0.35) 49%, rgba(142, 70, 16, 0.2) 62% 100%);
  background-size: 240% 100%;
  box-shadow:
    inset 0 0 0 1px rgba(255, 220, 151, 0.5),
    inset 0 0 11px rgba(110, 47, 8, 0.18);
  animation: last-move-sheen .68s cubic-bezier(.2, .7, .2, 1) both;
}
@keyframes last-move-sheen {
  from { background-position: 100% 0; }
  to { background-position: 0 0; }
}
.cell.selected {
  background: radial-gradient(circle, rgba(255, 230, 161, 0.27), rgba(190, 111, 31, 0.11) 70%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 238, 190, 0.78),
    inset 0 0 12px rgba(255, 205, 101, 0.2);
}
.cell.selected .koma {
  transform: translateY(-9%) rotate(var(--piece-rotation)) scale(1.06);
  filter:
    drop-shadow(0 1px 0 rgba(255, 250, 231, 0.82))
    drop-shadow(0 2px 0 var(--koma-edge))
    drop-shadow(0 4px 0 var(--koma-edge-dark))
    drop-shadow(0 10px 6px rgba(28, 13, 4, 0.6));
  animation: selection-lift .2s cubic-bezier(.18, .82, .22, 1);
}
@keyframes selection-lift {
  from { transform: translateY(0) rotate(var(--piece-rotation)) scale(1); }
}
@media (hover: hover) and (pointer: fine) {
  .cell:not(.selected):hover .koma {
    transform: translateY(-2%) rotate(var(--piece-rotation)) scale(1.012);
    filter:
      drop-shadow(0 1px 0 rgba(255, 252, 239, 0.86))
      drop-shadow(0 2px 0 var(--koma-edge))
      drop-shadow(0 3px 0 var(--koma-edge-dark))
      drop-shadow(0 7px 4px rgba(25, 11, 3, 0.5));
  }
}
.cell:active .koma {
  transform: translateY(1%) rotate(var(--piece-rotation)) scale(.985);
}
.cell.check-square {
  background: radial-gradient(circle, rgba(198, 48, 38, 0.5), rgba(116, 20, 15, 0.2) 72%);
  animation: check-breathe 1.15s ease-in-out infinite;
}
@keyframes check-breathe {
  50% { box-shadow: inset 0 0 0 2px rgba(244, 116, 91, 0.78), inset 0 0 16px rgba(187, 29, 22, 0.55); }
}

.cell.target::after {
  content: '';
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(255, 228, 168, 0.09);
  border: 1.5px solid rgba(252, 213, 133, 0.9);
  box-shadow:
    inset 0 1px 3px rgba(48, 20, 5, 0.52),
    0 1px 0 rgba(255, 240, 203, 0.38),
    0 0 0 3px rgba(79, 35, 8, 0.07);
  z-index: 2;
  pointer-events: none;
  animation: target-reveal .2s cubic-bezier(.2, .75, .2, 1) both;
}
.cell.target.capture::after {
  width: 78%;
  height: 80%;
  background: transparent;
  border: 2px solid rgba(153, 44, 34, 0.92);
  border-radius: 4px;
  box-shadow:
    inset 0 0 8px rgba(117, 22, 18, 0.2),
    0 0 0 1px rgba(255, 225, 183, 0.4);
}

.cell.hint-from {
  background: radial-gradient(circle, rgba(255, 228, 158, .23), rgba(154, 91, 28, .1) 72%);
  box-shadow:
    inset 0 0 0 2px rgba(118, 69, 22, .48),
    inset 0 0 11px rgba(255, 219, 139, .2);
}

.cell.hint-to::after {
  content: '';
  position: absolute;
  inset: 12%;
  z-index: 4;
  border: 2px solid rgba(114, 64, 18, .82);
  border-radius: 7px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 239, 190, .55),
    0 0 0 2px rgba(255, 211, 124, .2);
  pointer-events: none;
  animation: hint-focus-reveal .28s cubic-bezier(.2, .75, .2, 1) both;
}

@keyframes hint-focus-reveal {
  from { opacity: 0; transform: scale(.68); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes target-reveal {
  from { transform: scale(.58); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* 駒 */
.koma {
  --piece-rotation: 0deg;
  --grain-x: 50%;
  --grain-y: 42%;
  position: relative;
  width: 89%;
  height: 92%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--koma-face);
  background-image:
    radial-gradient(110% 62% at 42% 5%, rgba(255, 255, 255, 0.42), transparent 58%),
    linear-gradient(148deg, rgba(255, 255, 255, 0.18), rgba(116, 61, 19, 0.14));
  clip-path: polygon(50% 1%, 84.5% 16%, 98% 100%, 2% 100%, 15.5% 16%);
  color: var(--koma-text);
  font-weight: 800;
  font-family: 'Yu Mincho', 'Hiragino Mincho ProN', 'Noto Serif JP', serif;
  line-height: 1;
  z-index: 3;
  transform: rotate(var(--piece-rotation));
  transform-origin: 50% 52%;
  transition:
    transform 0.18s cubic-bezier(.18, .8, .22, 1),
    filter 0.18s ease;
  filter:
    drop-shadow(0 1px 0 rgba(255, 252, 239, 0.85))
    drop-shadow(0 2px 0 var(--koma-edge))
    drop-shadow(0 3px 0 var(--koma-edge-dark))
    drop-shadow(0 6px 3px rgba(25, 11, 3, 0.48));
}
.koma::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  clip-path: inherit;
  background-image: var(--koma-texture);
  background-size: 176% 176%;
  background-position: var(--grain-x) var(--grain-y);
  mix-blend-mode: multiply;
  opacity: 0.52;
  pointer-events: none;
}
.koma::after {
  content: '';
  position: absolute;
  inset: 2px 2px 1px;
  z-index: 1;
  clip-path: inherit;
  background:
    linear-gradient(108deg, rgba(255, 255, 255, 0.34), transparent 25% 70%, rgba(79, 37, 8, 0.14)),
    linear-gradient(180deg, transparent 69%, rgba(79, 36, 8, 0.2));
  box-shadow:
    inset 0 0 0 1px rgba(255, 249, 225, 0.25),
    inset 0 -2px rgba(91, 43, 13, 0.11);
  pointer-events: none;
}
.koma .kanji {
  position: relative;
  z-index: 2;
  transform: translateY(3%);
  text-shadow:
    0 .7px 0 rgba(0, 0, 0, 0.82),
    0 0 1px rgba(25, 13, 3, 0.25),
    0 1px 0 rgba(255, 255, 255, 0.11);
}
.koma.gote { --piece-rotation: 180deg; }
.board-grid.is-flipped .koma { --piece-rotation: 180deg; }
.board-grid.is-flipped .koma.gote { --piece-rotation: 0deg; }
.koma.promoted {
  color: #a62a20;
  text-shadow: 0 1px 0 rgba(255, 198, 156, 0.34);
}
.koma.small-label .kanji { font-size: 0.72em; letter-spacing: -0.05em; }
.koma.moving { animation: drop-in 0.18s ease-out; }
@keyframes drop-in {
  from { transform: translateY(-7%) rotate(var(--piece-rotation)) scale(1.12); filter: brightness(1.24); }
}
.koma.arrival-hidden { visibility: hidden; }
.koma.move-ghost,
.koma.capture-ghost {
  position: fixed;
  z-index: 1200;
  margin: 0;
  pointer-events: none;
  will-change: transform, filter, opacity;
}
.koma.capture-ghost {
  z-index: 1190;
  filter: saturate(.88) drop-shadow(0 7px 4px rgba(0, 0, 0, .38));
}
.koma.piece-landing {
  animation: piece-land .2s cubic-bezier(.2, .72, .2, 1);
}
.koma.promotion-reveal {
  animation: promotion-reveal .24s cubic-bezier(.2, .72, .2, 1);
}
@keyframes piece-land {
  0% {
    transform: translateY(-4%) rotate(var(--piece-rotation)) scale(1.025);
    filter: brightness(1.1) drop-shadow(0 7px 4px rgba(0,0,0,.36));
  }
  100% { transform: rotate(var(--piece-rotation)) scale(1); }
}
@keyframes promotion-reveal {
  0% {
    transform: translateY(-4%) rotate(var(--piece-rotation)) scale(1.025);
    opacity: .72;
    filter: sepia(.28) brightness(1.24) drop-shadow(0 7px 4px rgba(0,0,0,.34));
  }
  100% {
    transform: rotate(var(--piece-rotation)) scale(1);
    opacity: 1;
    filter: brightness(1);
  }
}
.cell.landing-ripple::after {
  content: '';
  position: absolute;
  inset: 14%;
  z-index: 2;
  border: 1px solid rgba(255, 232, 168, 0.66);
  border-radius: 3px;
  pointer-events: none;
  animation: landing-ripple .44s ease-out forwards;
}
@keyframes landing-ripple {
  from { transform: scale(.52); opacity: .82; box-shadow: 0 0 8px rgba(244, 185, 67, .3); }
  to { transform: scale(1.2); opacity: 0; box-shadow: 0 0 0 rgba(244, 185, 67, 0); }
}

/* 筋・段のラベル */
.coord-files, .coord-ranks {
  position: absolute;
  display: grid;
  color: rgba(239, 221, 190, 0.86);
  font-family: 'Yu Mincho', 'Hiragino Mincho ProN', 'Noto Serif JP', serif;
  font-size: 10px;
  pointer-events: none;
}
.coord-files {
  top: -15px; left: 3px; right: 3px;
  grid-template-columns: repeat(9, 1fr);
  text-align: center;
}
.coord-ranks {
  right: -14px; top: 3px; bottom: 3px;
  grid-template-rows: repeat(9, 1fr);
  align-items: center;
  text-align: center;
  width: 11px;
}

/* 状態バー */
.status-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 33px;
  padding: 3px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: rgba(13, 12, 10, 0.47);
  font-size: 0.78rem;
  color: var(--text-dim);
  transition: color 0.16s ease, border-color 0.16s ease, background-color 0.16s ease;
}
.status-strip.selection-active {
  border-color: rgba(226, 183, 95, 0.4);
  background: linear-gradient(90deg, rgba(226, 183, 95, 0.11), rgba(226, 183, 95, 0.035));
}
.status-strip.selection-active .move-text { color: #f4cf7c; }
.status-strip.thinking-active {
  border-color: rgba(121, 171, 209, 0.26);
  background: rgba(121, 171, 209, 0.07);
}
.status-strip.check-active {
  border-color: rgba(227, 109, 98, 0.46);
  background: rgba(227, 109, 98, 0.08);
}
.status-strip .badge {
  border-radius: 5px;
  padding: 2px 7px;
  font-weight: 700;
  font-size: 0.7rem;
}
.badge.check { background: var(--danger); color: #fff; }
.badge.thinking { background: var(--info); color: #06121c; }
.badge.online { background: #1e4a30; color: #9ce6b6; }
.badge.offline { background: #4a2020; color: #f0b4ae; }
.badge.reconnecting {
  background: #5a4218;
  color: #ffe0a0;
  border: 1px solid rgba(255, 214, 132, 0.28);
}
.status-strip.reconnecting-active {
  border-color: rgba(226, 183, 95, 0.48);
  background: linear-gradient(90deg, rgba(226, 183, 95, 0.1), rgba(226, 183, 95, 0.02));
}
.status-strip .move-text {
  flex: 1;
  text-align: right;
  color: var(--text);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding-top: 2px;
}
.action-bar .btn {
  min-height: 58px;
  padding: 4px 2px;
  font-size: 0.68rem;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  line-height: 1.15;
  border-color: #453e34;
  border-radius: 10px;
  color: #e9e2d7;
  background: linear-gradient(145deg, #2a2721, #1d1b17);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.035),
    0 3px 8px rgba(0, 0, 0, 0.16);
}
.action-bar .btn .icon {
  width: 20px;
  height: 20px;
  color: #d7cbb9;
  transition: transform .12s ease, color .15s ease;
}
.action-bar .btn:active .icon { transform: translateY(1px) scale(.9); }
.action-bar .btn:focus-visible {
  outline-offset: 1px;
  border-color: rgba(242, 203, 123, 0.72);
}
.action-bar #btn-resign { color: #e9c6c1; }
.action-bar #btn-resign .icon { color: #d58f87; }

/* ---------- モーダル / ボトムシート ---------- */

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(4px);
}
.sheet-backdrop.open { display: flex; }
.sheet {
  width: 100%;
  max-width: 520px;
  background-color: #211e1a;
  background-image:
    linear-gradient(rgba(33, 30, 26, 0.9), rgba(33, 30, 26, 0.9)),
    url('assets/washi-dark.jpg');
  background-size: auto, 460px 460px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(var(--safe-bottom) + 16px);
  max-height: calc(var(--app-h) * 0.88);
  overflow-y: auto;
  box-shadow: 0 -18px 46px rgba(0, 0, 0, 0.45);
  animation: sheet-up .24s cubic-bezier(.2, .78, .2, 1);
}
@keyframes sheet-up { from { transform: translateY(34px) scale(.992); opacity: 0.34; } }
.sheet h3 {
  margin: 0 0 4px;
  font-size: 1.05rem;
  text-align: center;
}
.sheet .sheet-sub {
  margin: 0 0 14px;
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.6;
}
.sheet-actions { display: flex; gap: 10px; margin-top: 14px; }
.sheet-actions .btn { flex: 1; }

.promo-choices { display: flex; gap: 12px; justify-content: center; margin: 6px 0 4px; }
.promo-choice {
  flex: 1;
  background: var(--bg-soft);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  min-height: 116px;
}
.promo-choice.recommend { border-color: var(--accent); }
.promo-choice .koma-slot { width: 46px; height: 50px; display: flex; }
.promo-choice .koma { font-size: 25px; }
.promo-choice .label { font-size: 0.85rem; font-weight: 700; }

/* 棋譜 */
.kifu-list {
  max-height: calc(var(--app-h) * 0.52);
  overflow-y: auto;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px;
}
.kifu-list.compact { max-height: calc(var(--app-h) * 0.26); }
.kifu-row {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  font-size: 0.88rem;
  cursor: pointer;
  min-height: 38px;
}
.kifu-row:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }
.kifu-row:hover { background: rgba(255, 255, 255, 0.07); }
.kifu-row.current { background: rgba(224, 169, 75, 0.22); }
.kifu-row .no {
  width: 30px;
  color: var(--text-dim);
  font-size: 0.74rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  flex: none;
}
.kifu-row .mv { flex: 1; font-weight: 600; }
.kifu-row .tm { font-size: 0.7rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.history-entry .history-open {
  width: 28px;
  height: 28px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid rgba(224, 169, 75, 0.42);
  border-radius: 8px;
  color: var(--accent);
  background: rgba(224, 169, 75, 0.08);
}
.history-entry .history-open .icon { width: 15px; height: 15px; }
.history-entry:focus-visible .history-open,
.history-entry:hover .history-open {
  border-color: var(--accent);
  background: rgba(224, 169, 75, 0.16);
}
.history-kifu-sheet { overflow: hidden; }
.history-kifu-text {
  margin: 0;
  width: 100%;
  min-height: calc(var(--app-h) * 0.28);
  max-height: calc(var(--app-h) * 0.54);
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(rgba(19, 17, 14, 0.96), rgba(19, 17, 14, 0.96)),
    url('assets/washi-dark.jpg');
  color: #eee5d7;
  font-family: "Noto Sans Mono", "Yu Gothic UI", "Meiryo", monospace;
  font-size: 0.76rem;
  line-height: 1.7;
  white-space: pre;
  text-align: left;
  direction: ltr;
  unicode-bidi: plaintext;
  overscroll-behavior: contain;
}

/* チャット */
.chat-log {
  max-height: calc(var(--app-h) * 0.38);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 6px 2px;
}
.chat-bubble {
  max-width: 82%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 0.87rem;
  line-height: 1.45;
  background: var(--panel-2);
  align-self: flex-start;
}
.chat-bubble.me { align-self: flex-end; background: #47351a; }
.chat-bubble .who { display: block; font-size: 0.66rem; color: var(--text-dim); margin-bottom: 2px; }
.phrase-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.phrase-grid .btn { font-size: 0.8rem; min-height: 42px; }

/* ルーム一覧 */
.room-list { display: grid; gap: 8px; }
.room-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  min-height: 58px;
  text-align: left;
  cursor: pointer;
}
.room-item .code {
  font-family: ui-monospace, monospace;
  font-size: 1.12rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--accent);
  flex: none;
}
.room-item .meta { flex: 1; font-size: 0.74rem; color: var(--text-dim); line-height: 1.5; }
.room-item .go { font-size: 1.2rem; color: var(--text-dim); }

/* 公開部屋：状態・条件と、参戦／観戦のボタン */
.room-item.public-room { cursor: default; flex-wrap: wrap; }
.room-item.public-room .meta { flex: 1 1 100%; min-width: 0; display: grid; gap: 2px; }
.room-item .room-status {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--accent);
}
.room-item.public-room[data-status='playing'] .room-status { color: var(--text-dim); }
.room-item .room-detail { white-space: pre-line; overflow-wrap: anywhere; color: var(--text); }
.room-item .room-actions { display: flex; gap: 8px; flex: none; margin-left: auto; }
.room-item .room-actions .btn { min-height: 40px; padding: 0 14px; font-size: 0.82rem; }

.code-display {
  text-align: center;
  background: var(--bg-soft);
  border: 1px dashed var(--accent);
  border-radius: var(--radius);
  padding: 16px 12px;
  margin-bottom: 12px;
}
.code-display .code-value {
  font-family: ui-monospace, monospace;
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: 0.28em;
  color: var(--accent);
  padding-left: 0.28em;
}
.code-display .code-label { font-size: 0.72rem; color: var(--text-dim); letter-spacing: 0.16em; }

.code-input {
  text-align: center;
  font-family: ui-monospace, monospace;
  font-size: 1.7rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  padding-left: 0.3em;
  min-height: 58px;
}

.waiting-dots::after {
  content: '';
  animation: dots 1.4s steps(4, end) infinite;
}
@keyframes dots { 0% { content: ''; } 25% { content: '・'; } 50% { content: '・・'; } 75% { content: '・・・'; } }

/* 結果 */
.result-hero { text-align: center; padding: 6px 0 12px; }
.result-hero .big {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  padding-left: 0.2em;
  margin: 0;
}
.result-hero .big.win { color: var(--accent); }
.result-hero .big.lose { color: var(--text-dim); }
.result-hero .big.draw { color: var(--info); }
.result-hero .reason { font-size: 0.86rem; color: var(--text-dim); margin-top: 6px; }
.result-rematch-status {
  min-height: 1.3em;
  margin: 10px 0 0 !important;
  color: #e8c77e !important;
}
.result-rematch-status:empty { display: none; }
.result-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
.result-actions #result-rematch { grid-column: 1 / -1; }
.result-actions .btn { min-width: 0; }

/* トースト */
#toast-host {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(var(--safe-bottom) + 84px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 80;
  pointer-events: none;
  padding: 0 16px;
}
.toast {
  background: rgba(20, 16, 13, 0.96);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.2s ease-out;
  max-width: 100%;
  text-align: center;
}
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }

/* 横向き（ランドスケープ）時の調整 */
@media (max-width: 500px) and (orientation: landscape) and (max-height: 520px) {
  .action-bar .btn { min-height: 38px; font-size: 0.6rem; }
  .action-bar .btn .ico { font-size: 0.9rem; }
  .player-bar { min-height: 34px; }
  .hand-tray { min-height: 36px; }
  .hand-koma { width: 28px; height: 31px; }
}

/* 小さい端末 */
@media (max-width: 500px) and (max-height: 680px) {
  .home-hero { padding: 10px 0 8px; }
  .home-hero .logo { font-size: 2.3rem; }
  .menu-item { min-height: 60px; padding: 11px 14px; }
  .player-bar { min-height: 39px; padding-top: 4px; padding-bottom: 4px; }
  .hand-tray { min-height: 34px; }
  .hand-koma { width: 30px; height: 33px; }
  .status-strip { min-height: 25px; }
  .action-bar .btn { min-height: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* =============================================================
 * 和風統一 UI v3 — 黒漆 / 墨和紙 / 榧 / 燻し真鍮
 * 盤の実在感を主役にし、画面間で同じ余白・罫線・操作語彙を使う。
 * ============================================================= */

:root {
  --bg: #090806;
  --bg-soft: #11100d;
  --panel: rgba(22, 20, 17, 0.96);
  --panel-2: #181612;
  --line: #514638;
  --line-strong: #786141;
  --line-soft: rgba(211, 174, 111, 0.16);
  --text: #f3ede3;
  --text-dim: #aaa092;
  --text-faint: #766d62;
  --accent: #d6a04c;
  --accent-2: #a96e25;
  --accent-soft: rgba(214, 160, 76, 0.12);
  --hinoki: #e5b35b;
  --bengara: #b55346;
  --danger: #d66f63;
  --scrollbar-track: rgba(202, 157, 81, 0.14);
  --scrollbar-thumb: #9b7239;
  --scrollbar-thumb-highlight: #c79446;
  --scrollbar-thumb-active: #e0b55d;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 18px;
  --tap: 46px;
  --font-mincho: 'Yu Mincho', 'Hiragino Mincho ProN', 'Noto Serif JP', serif;
  --font-gothic: 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Yu Gothic', 'Noto Sans JP', system-ui, sans-serif;
  --ease-shoji: cubic-bezier(.2, .76, .22, 1);
}

html[lang='ar'] {
  --font-mincho: 'Segoe UI', 'Noto Sans Arabic', Tahoma, Arial, sans-serif;
  --font-gothic: 'Segoe UI', 'Noto Sans Arabic', Tahoma, Arial, sans-serif;
}

html[lang='ar'] :is(
  .logo,
  .title-bar h2,
  .card h3,
  .menu-item .mi-title,
  .btn,
  .badge,
  .seg button,
  .rule-heading h3,
  .rule-term,
  .sheet h3,
  .pb-name
) {
  letter-spacing: 0;
}

html:is([lang='ko'], [lang^='zh'], [lang='ru'], [lang='hi'], [lang='bn'], [lang='th']) :is(
  .logo,
  .title-bar h2,
  .card h3,
  .menu-item .mi-title,
  .btn,
  .badge,
  .seg button,
  .rule-heading h3,
  .rule-term,
  .sheet h3,
  .pb-name
) {
  letter-spacing: 0;
}

body {
  font-family: var(--font-gothic);
  background-color: #050504;
  background-image:
    radial-gradient(ellipse at 50% 4%, rgba(109, 75, 37, 0.18), transparent 54%),
    linear-gradient(rgba(7, 7, 6, 0.82), rgba(7, 7, 6, 0.92)),
    url('assets/washi-dark.jpg');
  background-size: auto, auto, 480px 480px;
}

#device {
  background-color: var(--bg);
  background-image:
    linear-gradient(90deg, rgba(215, 164, 83, 0.07) 0, transparent 18%, transparent 82%, rgba(215, 164, 83, 0.035) 100%),
    linear-gradient(rgba(9, 8, 6, 0.91), rgba(9, 8, 6, 0.94)),
    url('assets/washi-dark.jpg');
  background-size: auto, auto, 430px 430px;
}

#device::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 100;
  border: 1px solid rgba(205, 158, 85, 0.28);
  border-radius: inherit;
  box-shadow:
    inset 0 1px rgba(255, 238, 202, 0.03),
    inset 0 0 30px rgba(0, 0, 0, 0.2);
  pointer-events: none;
}

@media (min-width: 501px) and (hover: hover) and (pointer: fine) {
  #device {
    box-shadow:
      0 0 0 7px #0e0d0b,
      0 0 0 8px #4b4134,
      0 0 0 9px rgba(201, 156, 84, 0.18),
      0 34px 78px rgba(0, 0, 0, 0.78),
      0 5px 16px rgba(0, 0, 0, 0.66),
      inset 0 1px rgba(255, 255, 255, 0.02);
  }
}

.screen {
  padding:
    calc(var(--safe-top) + 10px)
    calc(var(--safe-right) + 18px)
    calc(var(--safe-bottom) + 10px)
    calc(var(--safe-left) + 18px);
}

.screen:not(#screen-game) {
  background-image:
    linear-gradient(90deg, transparent 0 8px, rgba(203, 153, 75, 0.2) 8px 9px, transparent 9px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.008), transparent 36%);
}

.screen.active {
  animation: screen-enter-wa 0.22s var(--ease-shoji);
}

@keyframes screen-enter-wa {
  from {
    opacity: 0;
    transform: translateX(7px);
    filter: brightness(.86);
  }
  to {
    opacity: 1;
    transform: translateX(0);
    filter: brightness(1);
  }
}

.screen-scroll {
  padding: 0 2px 28px 0;
  scroll-padding-block: 12px;
}

:is(.screen-scroll, .sheet, .kifu-list, .chat-log, .history-kifu-text) {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

:is(.screen-scroll, .sheet, .kifu-list, .chat-log, .history-kifu-text)::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

:is(.screen-scroll, .sheet, .kifu-list, .chat-log, .history-kifu-text)::-webkit-scrollbar-track {
  background:
    linear-gradient(
      90deg,
      transparent 0 2px,
      var(--scrollbar-track) 2px 4px,
      transparent 4px
    );
}

:is(.screen-scroll, .sheet, .kifu-list, .chat-log, .history-kifu-text)::-webkit-scrollbar-thumb {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--scrollbar-thumb-highlight), var(--scrollbar-thumb)) padding-box;
  box-shadow: none;
}

:focus-visible {
  outline: 2px solid #e3bc70;
  outline-offset: 2px;
}

.title-bar {
  min-height: 54px;
  gap: 12px;
  margin: 0 0 12px;
  border-bottom: 1px solid rgba(202, 157, 81, 0.36);
  position: relative;
}

.title-bar::after {
  content: '';
  position: absolute;
  inset-inline-start: 0;
  bottom: -1px;
  width: 52px;
  height: 1px;
  background: var(--accent);
}

.title-bar h2 {
  font-family: var(--font-mincho);
  font-size: 1.16rem;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.btn {
  border-color: var(--line);
  background:
    linear-gradient(180deg, rgba(38, 34, 28, 0.94), rgba(21, 20, 17, 0.98));
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.88rem;
  letter-spacing: 0.055em;
  box-shadow:
    inset 0 1px rgba(255, 245, 222, 0.025),
    0 2px 7px rgba(0, 0, 0, 0.2);
  transition:
    transform 0.11s var(--ease-shoji),
    color 0.16s ease,
    background-color 0.16s ease,
    border-color 0.16s ease,
    box-shadow 0.16s ease;
}

@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) {
    border-color: var(--line-strong);
    background:
      linear-gradient(180deg, rgba(46, 40, 32, 0.96), rgba(24, 22, 18, 0.99));
    box-shadow:
      inset 0 1px rgba(255, 245, 222, 0.04),
      0 4px 10px rgba(0, 0, 0, 0.25);
  }
}

.btn:active {
  transform: translateY(1px) scale(.99);
  filter: brightness(1.06);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.28);
}

.btn.primary {
  background:
    linear-gradient(180deg, #e5b866 0%, #d89f43 52%, #b97827 100%);
  border-color: #efc777;
  color: #211608;
  box-shadow:
    inset 0 1px rgba(255, 247, 219, 0.5),
    inset 0 -1px rgba(74, 37, 7, 0.28),
    0 5px 14px rgba(65, 36, 9, 0.32);
}

.btn.danger {
  background: rgba(84, 36, 31, 0.58);
  border-color: rgba(181, 83, 70, 0.72);
  color: #f0b7af;
}

.btn.ghost {
  background: rgba(12, 11, 9, 0.24);
}

.btn.icon {
  border-color: rgba(205, 163, 97, 0.36);
  background: rgba(12, 11, 9, 0.52);
}

.card {
  background:
    linear-gradient(145deg, rgba(31, 28, 23, 0.86), rgba(18, 17, 14, 0.92));
  border-color: rgba(198, 158, 97, 0.3);
  border-radius: var(--radius);
  box-shadow:
    inset 0 1px rgba(255, 245, 222, 0.018),
    0 8px 20px rgba(0, 0, 0, 0.1);
}

.card h3 {
  color: #d8a455;
  font-family: var(--font-mincho);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.field > label {
  color: var(--text-dim);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
}

.control {
  min-height: 50px;
  background:
    linear-gradient(180deg, rgba(12, 11, 9, 0.95), rgba(19, 17, 14, 0.96));
  border-color: rgba(196, 151, 78, 0.42);
  border-radius: var(--radius-sm);
  font-family: var(--font-gothic);
  font-size: 0.96rem;
  box-shadow:
    inset 0 1px 5px rgba(0, 0, 0, 0.42),
    0 1px rgba(255, 234, 194, 0.02);
}

.control:focus {
  border-color: #d2a252;
  box-shadow:
    inset 0 1px 5px rgba(0, 0, 0, 0.42),
    0 0 0 1px rgba(210, 162, 82, 0.24);
}

.seg {
  gap: 0;
  padding: 3px;
  background: rgba(11, 10, 8, 0.78);
  border-color: rgba(196, 151, 78, 0.38);
  border-radius: var(--radius-sm);
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.42);
}

.seg button {
  min-height: 43px;
  border-radius: 4px;
  color: #b6ab9c;
  font-family: var(--font-gothic);
  font-size: 0.86rem;
  transition:
    color .15s ease,
    background-color .15s ease,
    box-shadow .15s ease,
    transform .1s ease;
}

.seg button + button {
  border-inline-start: 1px solid rgba(202, 157, 81, 0.12);
}

.seg button[aria-pressed='true'] {
  background:
    linear-gradient(180deg, #edc06e, #dca14a);
  color: #211608;
  box-shadow:
    inset 0 1px rgba(255, 246, 215, 0.45),
    0 1px 5px rgba(0, 0, 0, 0.26);
}

.hint {
  color: var(--text-dim);
  font-size: 0.78rem;
  line-height: 1.68;
}

/* ---------- ホーム：一枚の漆塗りの献立として読む ---------- */

#screen-home {
  padding-top: calc(var(--safe-top) + 16px);
}

#screen-home .screen-scroll {
  padding-inline: 4px 2px;
}

.home-hero {
  padding: 24px 0 24px;
}

.home-hero::after {
  width: 54px;
  margin-top: 15px;
  background: linear-gradient(90deg, transparent, #c99647 24% 76%, transparent);
}

.home-hero .logo {
  font-family: var(--font-mincho);
  font-size: 3.08rem;
  font-weight: 700;
  color: #ddb05f;
  letter-spacing: .3em;
  text-shadow:
    0 1px rgba(255, 234, 183, 0.12),
    0 4px 12px rgba(0, 0, 0, 0.5);
}

.home-hero .sub {
  margin-top: 8px;
  color: #b0a696;
  font-size: .7rem;
  letter-spacing: .38em;
}

#screen-home > .screen-scroll > .menu-grid {
  position: relative;
  gap: 0;
  overflow: hidden;
  padding-inline-end: 5px;
  border: 1px solid rgba(198, 151, 80, 0.36);
  border-radius: var(--radius);
  background:
    linear-gradient(145deg, rgba(24, 22, 18, 0.92), rgba(13, 12, 10, 0.94));
  box-shadow:
    inset 0 1px rgba(255, 241, 214, 0.025),
    8px 0 0 -7px rgba(179, 121, 44, 0.42),
    0 12px 24px rgba(0, 0, 0, 0.13);
}

#screen-home > .screen-scroll > .menu-grid::after {
  content: '';
  position: absolute;
  inset-block: 0;
  inset-inline-end: 0;
  width: 5px;
  background:
    linear-gradient(90deg, rgba(63, 35, 14, .72), rgba(154, 96, 37, .58) 50%, rgba(70, 39, 15, .8)),
    repeating-linear-gradient(0deg, transparent 0 16px, rgba(239, 188, 106, .12) 16px 17px);
  border-inline-start: 1px solid rgba(225, 171, 88, .2);
  pointer-events: none;
}

#screen-home .menu-item {
  min-height: 72px;
  padding: 11px 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

#screen-home .menu-item + .menu-item {
  border-top: 1px solid rgba(202, 157, 81, 0.18);
}

#screen-home .menu-item::before {
  content: '';
  position: absolute;
  inset-inline-start: 0;
  top: 20%;
  width: 2px;
  height: 60%;
  background: transparent;
  transition: background-color .16s ease;
}

#screen-home .menu-item {
  position: relative;
}

@media (hover: hover) and (pointer: fine) {
  #screen-home .menu-item:hover {
    border-color: transparent;
    background: linear-gradient(90deg, rgba(210, 158, 75, 0.1), rgba(210, 158, 75, 0.018) 66%, transparent);
    box-shadow: none;
  }
  #screen-home .menu-item:hover::before {
    background: var(--accent);
  }
}

.menu-item > span:not(.mi-icon) {
  flex: 1;
  min-width: 0;
}

.menu-item .mi-icon {
  width: 40px;
  height: 40px;
  border-color: rgba(214, 160, 76, 0.44);
  border-radius: 9px;
  color: #d7a551;
  background:
    linear-gradient(145deg, rgba(214, 160, 76, 0.1), rgba(214, 160, 76, 0.025));
  box-shadow:
    inset 0 1px rgba(255, 235, 194, 0.04),
    0 2px 6px rgba(0, 0, 0, 0.2);
}

.menu-item .mi-title {
  font-family: var(--font-mincho);
  font-size: 1rem;
  letter-spacing: .035em;
}

.menu-item .mi-desc {
  color: #a89e90;
  font-size: .71rem;
  line-height: 1.45;
}

.menu-item .mi-status {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  margin-top: 3px;
  color: #bca77f;
  font-size: .62rem;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.mi-status-dot {
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: 50%;
  background: #817669;
  box-shadow: 0 0 0 2px rgba(129, 118, 105, .12);
}

.mi-status[data-state='connecting'] .mi-status-dot {
  background: #d5a14e;
  box-shadow: 0 0 0 2px rgba(213, 161, 78, .16);
  animation: connection-dot-pulse 1.05s ease-in-out infinite;
}

.mi-status[data-state='online'] .mi-status-dot {
  background: #81ad78;
  box-shadow: 0 0 0 2px rgba(129, 173, 120, .16);
}

.mi-status[data-state='offline'] .mi-status-dot { background: #b96d61; }

@keyframes connection-dot-pulse {
  50% { opacity: .45; transform: scale(.78); }
}

.menu-chevron {
  width: 18px;
  height: 18px;
  color: #c99748;
  stroke-width: 1.7;
  opacity: .9;
  flex: none;
}

html[dir='rtl'] .menu-chevron {
  transform: rotate(180deg);
}

#screen-home .card {
  margin-top: 14px !important;
  margin-bottom: 10px;
  padding: 13px 0 12px;
  border-width: 1px 0;
  border-color: rgba(202, 157, 81, 0.28);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

#screen-home .card h3 {
  margin-inline: 0;
}

.stat-row {
  gap: 7px;
}

.stat-row > div {
  padding: 9px 4px;
  border-color: rgba(196, 151, 78, 0.28);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(180deg, rgba(20, 18, 15, 0.7), rgba(10, 9, 8, 0.7));
}

.stat-row b {
  color: #d8a455;
  font-family: var(--font-mincho);
  font-size: 1.4rem;
}

#screen-home > .screen-scroll > .row .btn {
  min-width: 0;
  min-height: 47px;
  padding-inline: 8px;
  font-family: var(--font-mincho);
  font-size: .86rem;
  background: rgba(11, 10, 8, 0.36);
}

/* ---------- セットアップ / 設定 / 戦績 / 通信 ---------- */

:is(#screen-ai, #screen-local, #screen-online, #screen-settings, #screen-record) .card {
  padding: 15px 3px 17px;
  margin-bottom: 7px;
  border-width: 1px 0 0;
  border-color: rgba(204, 158, 81, 0.34);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

:is(#screen-ai, #screen-local, #screen-online, #screen-settings, #screen-record) .card h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  color: #d9a552;
  font-family: var(--font-mincho);
  font-size: .96rem;
  letter-spacing: .1em;
}

:is(#screen-ai, #screen-local, #screen-online, #screen-settings, #screen-record) .card h3::after {
  content: '';
  height: 1px;
  flex: 1;
  background: linear-gradient(90deg, rgba(205, 158, 81, 0.52), transparent);
}

#screen-ai .screen-scroll > .card:first-child,
#screen-local .screen-scroll > .card:first-child,
#screen-settings .screen-scroll > .card:first-child,
#screen-record .screen-scroll > .card:first-child {
  border-top: 0;
  padding-top: 4px;
}

:is(#screen-ai, #screen-local) .btn.primary.block {
  min-height: 52px;
  margin-top: 11px !important;
  font-family: var(--font-mincho);
  font-size: 1rem;
  letter-spacing: .12em;
}

#screen-settings .field {
  margin-bottom: 13px;
}

#screen-settings .switch {
  min-height: 47px;
  border-bottom: 1px solid rgba(202, 157, 81, 0.1);
  font-size: .88rem;
  transition: color .18s ease, background .18s ease;
}

#screen-settings .switch:focus-within {
  color: #fff4dd;
  background: rgba(214, 160, 76, .055);
}

.switch .track {
  width: 46px;
  height: 27px;
  border: 1px solid rgba(198, 151, 78, 0.28);
  background: #29251f;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, .32);
}

.switch .track::after {
  top: 3px;
  left: 3px;
  width: 19px;
  height: 19px;
  border: 1px solid rgba(255, 245, 221, 0.5);
  background: #eee7db;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .32);
}

.switch input:checked + .track {
  border-color: #e2b15c;
  background: linear-gradient(180deg, #d9a447, #b97827);
}

.switch input:checked + .track::after {
  transform: translateX(19px);
}

html[dir='rtl'] .switch .track::after {
  left: auto;
  right: 3px;
}

html[dir='rtl'] .switch input:checked + .track::after {
  transform: translateX(-19px);
}

.resume-game {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: start;
  gap: 3px;
  min-width: 0;
  padding-block: 10px;
  text-align: start;
}

.resume-title {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  color: var(--text);
  font-family: var(--font-mincho);
  font-weight: 800;
  line-height: 1.35;
  letter-spacing: .05em;
}

.resume-meta {
  max-width: 100%;
  overflow: hidden;
  color: var(--text-dim);
  font-size: .7rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.title-bar h2[tabindex='-1']:focus,
.home-hero h1[tabindex='-1']:focus {
  outline: none;
}

.volume-control {
  padding: 8px 0 11px;
  border-bottom: 1px solid rgba(202, 157, 81, 0.1);
}

.volume-control input[type='range']::-webkit-slider-runnable-track {
  height: 3px;
  background: linear-gradient(
    90deg,
    #c38b37 0 var(--volume-fill, 72%),
    #3b352d var(--volume-fill, 72%) 100%
  );
}

.volume-control input[type='range']::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  margin-top: -7px;
  border: 1px solid #f0cf8e;
  background: #c99342;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .42);
}

/* ---------- ルール：カードではなく一続きの読み物 ---------- */

#rules-body {
  padding-inline: 2px 5px;
}

.rule-card {
  margin: 0 0 14px;
  padding: 0;
  overflow: visible;
  border-width: 1px 0 0;
  border-color: rgba(205, 158, 81, 0.43);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.rule-heading {
  min-height: 50px;
  padding: 10px 2px 9px;
  border-bottom: 1px solid rgba(205, 158, 81, 0.42);
  background: linear-gradient(90deg, rgba(203, 147, 67, 0.1), transparent 66%);
}

.rule-number {
  flex-basis: 29px;
  width: 29px;
  height: 29px;
  border-color: rgba(226, 183, 95, 0.7);
  color: #e5b761;
  background: rgba(8, 7, 6, 0.46);
  font-family: var(--font-mincho);
  font-size: .76rem;
}

.rule-card .rule-heading h3 {
  color: #dfad59;
  font-family: var(--font-mincho);
  font-size: 1rem;
  letter-spacing: .075em;
}

.rule-lead {
  padding: 13px 5px 14px;
  border-bottom: 1px solid rgba(202, 157, 81, 0.13);
  color: #ddd5ca;
  font-size: .81rem;
  line-height: 1.78;
}

.rule-list {
  padding: 0 5px 5px;
}

.rule-item {
  padding: 12px 0 11px;
}

.rule-item + .rule-item {
  border-top: 1px solid rgba(202, 157, 81, 0.12);
}

.rule-term {
  margin-bottom: 5px;
  color: #dec18b;
  font-family: var(--font-mincho);
  font-size: .8rem;
  letter-spacing: .04em;
}

.rule-term::before {
  width: 6px;
  height: 6px;
  margin-inline-end: 8px;
  border-radius: 1px;
  background: #ce9743;
  box-shadow: none;
  transform: rotate(45deg);
}

.rule-text {
  color: #aaa195;
  font-size: .77rem;
  line-height: 1.78;
}

/* =============================================================
 * v1.5 — 振り返り・初心者支援・アクセシビリティ
 * ============================================================= */

.resume-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 8px;
  margin-top: 12px;
}
.resume-panel[hidden] { display: none; }
.resume-panel .resume-game { margin: 0; min-width: 0; }
.resume-discard {
  min-width: 66px;
  padding-inline: 10px;
}

.field-error {
  min-height: 1.25em;
  margin: 5px 0 0;
  color: #ff9b8f;
  font-size: .74rem;
  line-height: 1.45;
}
.field-error:empty { display: none; }
.control[aria-invalid='true'] {
  border-color: var(--danger);
  box-shadow: 0 0 0 2px rgba(227, 109, 98, .14);
}

.game-guide {
  min-height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 4px 10px;
  border: 1px solid rgba(225, 173, 80, .25);
  border-radius: 8px;
  background: rgba(225, 173, 80, .07);
  color: #ead6af;
  font-size: .72rem;
  line-height: 1.35;
  text-align: center;
}
.game-guide:empty { display: none; }

.game-guide-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-guide-action {
  min-width: max-content;
  height: calc(var(--game-guide-row-size, 26px) - 4px);
  min-height: 16px;
  max-height: 22px;
  padding: 0 7px;
  border: 0;
  border-inline-start: 1px solid rgba(225, 173, 80, .32);
  background: transparent;
  color: #efcf91;
  font: inherit;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.game-guide-action.close {
  width: 22px;
  min-width: 22px;
  padding: 0;
  font-size: .9rem;
}

.game-guide-action:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
  border-radius: 4px;
}

.review-controls {
  display: grid;
  grid-template-columns: 42px 42px minmax(62px, 1fr) 42px 42px;
  gap: 5px;
  align-items: center;
}
.review-controls[hidden] { display: none; }
.review-controls .btn {
  min-height: 38px;
  padding: 5px;
  font-size: .72rem;
}
.review-controls output {
  min-width: 0;
  color: #efd091;
  font-size: .75rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.review-controls .review-close {
  grid-column: 1 / -1;
  min-height: 36px;
}
#screen-game.review-mode .action-bar { display: none; }
#screen-game.review-mode .status-strip {
  border-color: rgba(225, 173, 80, .45);
}

.history-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 8px 0 12px;
}
.history-filters label {
  display: grid;
  gap: 5px;
  color: var(--text-dim);
  font-size: .72rem;
}
.history-filters .control {
  min-height: 40px;
  padding: 7px 30px 7px 9px;
  font-size: .78rem;
}
html[dir='rtl'] .history-filters .control {
  padding: 7px 9px 7px 30px;
}
.history-entry .no.void { color: var(--text-dim); }
.history-entry .no {
  width: 38px;
  white-space: nowrap;
}
.history-entry .mv {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-entry .mode-label {
  display: inline-flex;
  align-items: center;
  margin-inline-start: 6px;
  padding: 1px 5px;
  border: 1px solid rgba(225, 173, 80, .28);
  border-radius: 999px;
  color: #cbb892;
  font-size: .61rem;
  font-weight: 600;
  vertical-align: .12em;
}
.record-reset-zone {
  display: flex;
  justify-content: center;
  padding: 3px 0 18px;
}
.record-reset-zone .btn {
  min-height: 38px;
  font-size: .75rem;
}

.rules-tools {
  position: sticky;
  top: 0;
  z-index: 4;
  margin: -1px -1px 13px;
  padding: 2px 2px 12px;
  border-bottom: 1px solid rgba(205, 158, 81, .3);
  background:
    linear-gradient(rgba(10, 9, 7, .98), rgba(10, 9, 7, .94)),
    url('assets/washi-dark.jpg');
}
.rules-search-label {
  display: block;
  margin-bottom: 6px;
  color: #d8b873;
  font-size: .74rem;
  font-weight: 700;
}
.rules-tools .control {
  min-height: 42px;
}
.rule-toc {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-top: 8px;
  padding: 1px 1px 6px;
  scrollbar-width: thin;
  overscroll-behavior-inline: contain;
}
.rule-toc button {
  flex: none;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid rgba(205, 158, 81, .32);
  border-radius: 999px;
  background: rgba(205, 158, 81, .07);
  color: #d6c4a3;
  font: inherit;
  font-size: .7rem;
  cursor: pointer;
}
.rule-toc button:hover,
.rule-toc button:focus-visible {
  border-color: var(--accent);
  color: #ffe2a2;
}
.rule-card[hidden] { display: none; }
.rule-card { scroll-margin-top: 132px; }
.rule-search-empty {
  padding: 8px 2px 2px;
  text-align: center;
}

.history-kifu-sheet .sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.history-kifu-sheet #history-kifu-replay {
  grid-column: 1 / -1;
}
.history-kifu-sheet #history-kifu-replay[hidden] { display: none; }

.result-actions #result-review { grid-column: 1 / -1; }

html[data-text-size='large'] {
  font-size: 17px;
}
html[data-contrast='high'] {
  --text: #fffaf1;
  --text-dim: #d7cec1;
  --line: #6c6254;
  --line-soft: rgba(245, 218, 174, .25);
  --accent: #f2bd5b;
}
html[data-contrast='high'] .hint,
html[data-contrast='high'] .mi-desc,
html[data-contrast='high'] .rule-text,
html[data-contrast='high'] .sheet-sub {
  color: #d7cec1;
}
html[data-motion='reduced'] *,
html[data-motion='reduced'] *::before,
html[data-motion='reduced'] *::after {
  scroll-behavior: auto !important;
  animation-duration: .001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .001ms !important;
}

/* ---------- 対局：盤以外は細い漆のレールとして整理 ---------- */

#screen-game {
  padding-top: calc(var(--safe-top) + 6px);
  padding-right: calc(var(--safe-right) + 7px);
  padding-bottom: calc(var(--safe-bottom) + 7px);
  padding-left: calc(var(--safe-left) + 7px);
}

.game-wrap {
  gap: 4px;
}

.player-bar {
  min-height: 43px;
  padding: 5px 10px;
  border-color: rgba(202, 157, 81, 0.26);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(105deg, rgba(25, 23, 19, .9), rgba(11, 10, 8, .92));
  box-shadow:
    inset 0 1px rgba(255, 244, 218, 0.02),
    0 2px 7px rgba(0, 0, 0, .14);
}

.player-bar::after {
  top: 6px;
  bottom: 6px;
  width: 2px;
}

.player-bar.turn-active {
  border-color: rgba(222, 173, 87, 0.8);
  background:
    linear-gradient(105deg, rgba(41, 34, 24, .94), rgba(14, 13, 11, .96));
  box-shadow:
    inset 0 0 0 1px rgba(255, 222, 155, 0.05),
    0 3px 8px rgba(0, 0, 0, .18);
}

.player-bar.turn-active::after {
  box-shadow: none;
}

.player-bar.turn-active .pb-name,
.player-bar.turn-active .pb-clock {
  color: #e5c58b;
}

.player-bar.turn-active::before {
  background: linear-gradient(105deg, transparent 22%, rgba(231, 190, 111, 0.12) 49%, transparent 76%);
  animation-duration: .42s;
}

.pb-name {
  font-family: var(--font-mincho);
  letter-spacing: .04em;
}

.pb-clock {
  font-family: var(--font-mincho);
  color: #e9dfcf;
}

.pb-tag {
  border-radius: 4px;
  background: rgba(0, 0, 0, .14);
}

.hand-tray {
  min-height: 38px;
  padding-inline: 8px;
  border-color: rgba(202, 157, 81, 0.22);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(90deg, rgba(9, 8, 7, .74), rgba(19, 17, 14, .58));
  box-shadow: inset 0 1px 5px rgba(0, 0, 0, .26);
}

.hand-tray.empty::before {
  color: #9f9587;
  font-size: .7rem;
}

.board-area {
  padding: 14px 8px 3px 0;
}

.board-area::before {
  background: radial-gradient(ellipse at 50% 46%, rgba(184, 112, 40, 0.11), transparent 70%);
  filter: blur(11px);
}

.status-strip {
  min-height: 31px;
  padding-inline: 5px;
  border-width: 1px 0 0;
  border-color: rgba(202, 157, 81, 0.18);
  border-radius: 0;
  background: transparent;
}

.status-strip.selection-active,
.status-strip.thinking-active,
.status-strip.check-active {
  border-color: rgba(214, 160, 76, 0.48);
  background: linear-gradient(90deg, rgba(214, 160, 76, 0.08), transparent);
}

.action-bar {
  position: relative;
  gap: 5px;
  padding-top: 9px;
  border-top: 1px solid rgba(202, 157, 81, 0.28);
  background-image:
    linear-gradient(30deg, transparent 47%, rgba(202, 157, 81, 0.025) 48% 52%, transparent 53%),
    linear-gradient(150deg, transparent 47%, rgba(202, 157, 81, 0.025) 48% 52%, transparent 53%);
  background-size: 18px 31px;
}

.action-bar .btn {
  min-height: 59px;
  border-color: rgba(202, 157, 81, 0.25);
  border-radius: var(--radius-sm);
  color: #e5ddd0;
  background:
    linear-gradient(180deg, rgba(34, 31, 26, .95), rgba(16, 15, 13, .98));
  box-shadow:
    inset 0 1px rgba(255, 246, 222, .025),
    0 2px 7px rgba(0, 0, 0, .16);
}

.action-bar .btn .icon {
  color: #cfc3b2;
  stroke-width: 1.65;
}

.action-bar #btn-resign,
.action-bar #btn-resign .icon {
  color: #c97b70;
}

/* ---------- ボトムシート：墨の和紙を一枚持ち上げる ---------- */

.sheet-backdrop {
  background: rgba(3, 3, 2, 0.72);
  backdrop-filter: blur(2.5px) saturate(.72);
}

.sheet-backdrop.open {
  animation: veil-in .18s ease-out;
}

@keyframes veil-in {
  from { background-color: rgba(3, 3, 2, 0); }
}

.sheet {
  max-width: none;
  max-height: calc(var(--app-h) * .9);
  padding: 29px 17px calc(var(--safe-bottom) + 15px);
  border-color: rgba(207, 161, 88, 0.45);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background-color: #15130f;
  background-image:
    linear-gradient(rgba(20, 18, 15, 0.92), rgba(17, 16, 13, 0.96)),
    url('assets/washi-dark.jpg');
  background-size: auto, 420px 420px;
  box-shadow:
    0 -18px 44px rgba(0, 0, 0, .52),
    inset 0 1px rgba(255, 238, 204, .035);
  animation: sheet-up-wa .22s var(--ease-shoji);
  position: relative;
}

.sheet::before {
  content: '';
  position: absolute;
  top: 10px;
  left: 50%;
  width: 46px;
  height: 4px;
  border-radius: 99px;
  transform: translateX(-50%);
  background: #887053;
  box-shadow: inset 0 1px rgba(255, 240, 210, .12);
}

@keyframes sheet-up-wa {
  from {
    transform: translateY(38px) scale(.992);
    opacity: .24;
  }
}

.sheet h3 {
  margin: 0;
  padding: 0 0 9px;
  border-bottom: 1px solid rgba(202, 157, 81, 0.35);
  color: #eee5d7;
  font-family: var(--font-mincho);
  font-size: 1.13rem;
  letter-spacing: .08em;
}

.sheet .sheet-sub {
  margin: 7px 0 11px;
  color: #9f9587;
  font-size: .75rem;
}

.sheet .menu-grid {
  gap: 0;
  border-top: 1px solid rgba(202, 157, 81, .18);
  border-bottom: 1px solid rgba(202, 157, 81, .18);
}

.sheet .menu-item {
  min-height: 69px;
  padding: 10px 7px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.sheet .menu-item + .menu-item {
  border-top: 1px solid rgba(202, 157, 81, .16);
}

@media (hover: hover) and (pointer: fine) {
  .sheet .menu-item:hover {
    border-color: rgba(202, 157, 81, .16);
    background: linear-gradient(90deg, rgba(203, 151, 67, .08), transparent 72%);
    box-shadow: none;
  }
}

.sheet .menu-item .mi-icon {
  width: 39px;
  height: 39px;
}

.sheet .menu-item .mi-title {
  font-size: .93rem;
}

.sheet .menu-item .mi-desc {
  font-size: .69rem;
}

#menu-quit .mi-icon,
#menu-quit .mi-title,
#menu-quit .menu-chevron {
  color: #c57b6f;
}

.sheet-actions {
  margin-top: 12px;
}

.sheet-actions .btn {
  background: rgba(9, 8, 7, .36);
}

.sheet-actions .btn.primary {
  background: linear-gradient(180deg, #e5b866, #c98934);
}

.promo-choice,
.kifu-list,
.history-kifu-text,
.code-display,
.room-item {
  border-color: rgba(198, 151, 78, .32);
  border-radius: var(--radius-sm);
  background-color: rgba(10, 9, 8, .66);
}

.toast {
  border-color: rgba(208, 161, 87, .52);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(180deg, rgba(31, 27, 22, .98), rgba(14, 13, 11, .98));
  box-shadow: 0 7px 22px rgba(0, 0, 0, .48);
}

html[dir='rtl'] .menu-item {
  text-align: right;
}

html[dir='rtl'] .title-bar::after {
  inset-inline-start: 0;
}

@media (max-width: 500px) and (max-height: 680px) {
  .screen {
    padding-inline: calc(var(--safe-left) + 13px) calc(var(--safe-right) + 13px);
  }
  .home-hero {
    padding: 12px 0 14px;
  }
  .home-hero .logo {
    font-size: 2.35rem;
  }
  #screen-home .menu-item {
    min-height: 60px;
    padding-block: 8px;
  }
  .sheet .menu-item {
    min-height: 60px;
  }
}

/* ---------- 対局：持ち駒の増減で盤を動かさない ---------- */

:root {
  --hand-tray-row-size: 46px;
  --game-guide-row-size: 30px;
}

.hand-tray {
  box-sizing: border-box;
  flex: 0 0 var(--hand-tray-row-size);
  block-size: var(--hand-tray-row-size);
  min-block-size: var(--hand-tray-row-size);
  max-block-size: var(--hand-tray-row-size);
  flex-wrap: nowrap;
}

.game-guide {
  box-sizing: border-box;
  flex: 0 0 var(--game-guide-row-size);
  block-size: var(--game-guide-row-size);
  min-block-size: var(--game-guide-row-size);
  max-block-size: var(--game-guide-row-size);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.game-guide:empty {
  display: flex;
  visibility: hidden;
}

@media (max-width: 500px) and (max-height: 680px) {
  :root {
    --hand-tray-row-size: 40px;
    --game-guide-row-size: 28px;
  }
}

@media (max-width: 500px) and (orientation: landscape) and (max-height: 520px) {
  :root {
    --hand-tray-row-size: 38px;
    --game-guide-row-size: 26px;
  }
}

/* ---------- 対局：iPhone SEなど高さの低いSafari ---------- */

@media (max-width: 500px) and (max-height: 700px) {
  :root {
    --hand-tray-row-size: 34px;
    --game-guide-row-size: 22px;
  }

  #screen-game {
    padding-top: calc(var(--safe-top) + 4px);
    padding-right: calc(var(--safe-right) + 5px);
    padding-bottom: calc(var(--safe-bottom) + 4px);
    padding-left: calc(var(--safe-left) + 5px);
  }

  .game-wrap { gap: 2px; }

  .player-bar {
    flex: 0 0 34px;
    min-height: 34px;
    height: 34px;
    padding: 2px 8px;
    gap: 6px;
  }

  .player-bar::after {
    top: 4px;
    bottom: 4px;
  }

  .pb-mark {
    width: 20px;
    font-size: .92rem;
  }

  .pb-name { font-size: .79rem; }
  .pb-tag { padding-inline: 4px; font-size: .55rem; }
  .pb-clock { min-width: 52px; font-size: .94rem; }

  .hand-tray {
    padding: 1px 6px;
    gap: 3px;
  }

  .hand-tray.empty::before { font-size: .62rem; }

  .hand-koma {
    width: 27px;
    height: 30px;
  }

  .hand-koma .koma { font-size: 15px; }

  .hand-koma .count {
    right: -2px;
    bottom: 0;
    min-width: 14px;
    height: 14px;
    line-height: 12px;
    font-size: .58rem;
  }

  .board-area { padding: 5px 6px 1px 0; }

  .status-strip {
    flex: 0 0 24px;
    min-height: 24px;
    height: 24px;
    padding: 1px 4px;
    gap: 5px;
    font-size: .68rem;
  }

  .status-strip .badge {
    padding: 1px 5px;
    font-size: .61rem;
  }

  .game-guide {
    padding: 1px 7px;
    font-size: .63rem;
    line-height: 1.15;
  }

  .action-bar {
    gap: 3px;
    padding-top: 3px;
  }

  .action-bar .btn {
    min-height: 46px;
    padding: 2px 1px;
    gap: 1px;
    font-size: .61rem;
  }

  .action-bar .btn .icon {
    width: 17px;
    height: 17px;
  }
}

@media (max-width: 500px) and (max-height: 580px) {
  :root {
    --hand-tray-row-size: 30px;
    --game-guide-row-size: 0px;
  }

  #screen-game {
    padding-top: calc(var(--safe-top) + 2px);
    padding-right: calc(var(--safe-right) + 4px);
    padding-bottom: calc(var(--safe-bottom) + 2px);
    padding-left: calc(var(--safe-left) + 4px);
  }

  .player-bar {
    flex-basis: 31px;
    min-height: 31px;
    height: 31px;
  }

  .hand-koma {
    width: 25px;
    height: 28px;
  }

  .game-guide {
    display: none !important;
    padding: 0;
    border: 0;
  }

  .status-strip {
    flex-basis: 22px;
    min-height: 22px;
    height: 22px;
  }

  .action-bar { padding-top: 2px; }

  .action-bar .btn {
    min-height: 40px;
    font-size: .58rem;
  }

  .action-bar .btn .icon {
    width: 15px;
    height: 15px;
  }
}
