/* 藍染めの卓に、白磁のコースターを伏せる。一画面に収まる縦長レイアウト。 */
:root {
  --ai: #14203d;        /* 藍：卓布 */
  --ai-2: #1d2c52;      /* 一段明るい藍：席 */
  --ai-3: #2f4477;      /* 縫い目・罫 */
  --kinari: #f1e8d4;    /* 生成り：文字と白磁 */
  --hai: #a9b2ca;       /* 灰：補足文字 */
  --tsubaki: #d6334a;   /* 椿の赤 */
  --kin: #e2b04a;       /* 黄土：強調 */
  --sumi: #1a1b24;      /* 墨：ドクロ面 */
  --font-display: 'Dela Gothic One', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  --font-body: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'Noto Sans JP', system-ui, sans-serif;
  --disc: clamp(34px, 10vw, 44px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background-color: var(--ai);
  background-image:
    repeating-linear-gradient(90deg, transparent 0 22px, rgba(241, 232, 212, 0.035) 22px 24px, transparent 24px 46px),
    repeating-linear-gradient(0deg, transparent 0 22px, rgba(241, 232, 212, 0.035) 22px 24px, transparent 24px 46px);
  color: var(--kinari);
  font-family: var(--font-body);
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
button:focus-visible { outline: 2px solid var(--kin); outline-offset: 2px; }

.app {
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 10px max(12px, env(safe-area-inset-bottom, 0px));
}

/* ---- ヘッダー ---- */
.bar { display: flex; align-items: center; gap: 12px; }
.logo { font-family: var(--font-display); font-weight: 400; font-size: 22px; margin: 0; letter-spacing: 0.08em; }
.round { color: var(--hai); font-size: 13px; flex: 1; }
.ghost {
  background: none; border: 1px solid var(--ai-3); border-radius: 999px;
  padding: 5px 12px; font-size: 13px; color: var(--hai); cursor: pointer;
}

/* ---- 円盤（白磁のコースター） ---- */
.disc {
  width: var(--disc); height: var(--disc); border-radius: 50%;
  display: grid; place-items: center; flex: none;
  background: radial-gradient(circle, var(--kinari) 0 52%, var(--ai-3) 53% 58%, var(--kinari) 59%);
  box-shadow: 0 3px 0 #b9ad93, 0 5px 8px rgba(0, 0, 0, 0.35);
  position: relative;
}
.disc svg { width: 78%; height: 78%; }
.disc.face-F { background: var(--kinari); }
.disc.face-S { background: var(--sumi); box-shadow: 0 3px 0 #000, 0 5px 8px rgba(0, 0, 0, 0.35); }
.disc.known { opacity: 1; }
.disc.known svg { opacity: 0.55; }
.disc.flip-in { animation: flip 0.45s ease-out; }
@keyframes flip { from { transform: rotateY(90deg) scale(1.15); } to { transform: none; } }
.disc.empty { background: none; box-shadow: none; border: 2px dashed var(--ai-3); }

/* 伏せ山：少しずつずらして積む */
.pile { position: relative; height: calc(var(--disc) + 24px); display: flex; align-items: flex-end; justify-content: center; }
.pile .disc { position: absolute; left: 50%; margin-left: calc(var(--disc) / -2); }
.pile-count { position: absolute; right: 0; bottom: 0; font-size: 12px; font-weight: 700; color: var(--hai); }

/* ---- 相手の席 ---- */
.opponents { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seat {
  background: var(--ai-2); border: 2px solid transparent; border-radius: 14px;
  padding: 10px; display: grid; gap: 6px; position: relative; text-align: left;
  min-width: 0;
}
.seat.active { border-color: var(--kin); }
.seat.out { opacity: 0.45; }
.seat.target { border-color: var(--tsubaki); cursor: pointer; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(214, 51, 74, 0.35); } }
.seat-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.crest {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; border: 2px solid var(--kinari);
  font-weight: 700; font-size: 19px; line-height: 1;
}
.seat-name { font-weight: 700; }
.seat-blurb { font-size: 11px; color: var(--hai); display: block; }
.seat-meta { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--hai); }
.bubble {
  position: absolute; top: -8px; right: 8px; background: var(--kinari); color: var(--sumi);
  border-radius: 10px; padding: 2px 9px; font-weight: 700; font-size: 14px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
.bubble.bid { background: var(--kin); }
.bubble.pass { background: var(--hai); }
.bubble.pop { animation: pop 0.3s ease-out; }
@keyframes pop { from { transform: scale(0.4); } to { transform: none; } }

.points { display: inline-flex; gap: 3px; }
.points i { width: 12px; height: 12px; transform: rotate(45deg); border: 2px solid var(--kin); display: inline-block; }
.points i.on { background: var(--kin); }
.mate { font-size: 11px; font-weight: 700; color: var(--sumi); background: var(--kin); border-radius: 4px; padding: 1px 5px; margin-left: 6px; }
.seat-meta .mate { margin-left: 0; margin-right: auto; margin-inline-start: 6px; }
.pips { display: inline-flex; gap: 3px; }
.pips i { width: 8px; height: 8px; border-radius: 50%; background: var(--kinari); display: inline-block; }
.pips i.lost { background: none; border: 1.5px solid var(--ai-3); }

/* ---- 場 ---- */
.table {
  display: grid; align-content: center; gap: 8px; text-align: center; min-height: 0;
  border-top: 1px dashed var(--ai-3); border-bottom: 1px dashed var(--ai-3); padding-block: 8px;
}
.bidline { display: flex; justify-content: center; align-items: baseline; gap: 8px; min-height: 52px; }
.bid-num { font-family: var(--font-display); font-size: 46px; line-height: 1; color: var(--kin); }
.bid-unit { font-size: 15px; }
.bid-who { font-size: 13px; color: var(--hai); }
.table-total { font-size: 13px; color: var(--hai); }
.ladder { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px 2px; min-height: 26px; font-size: 12.5px; }
.rung { border: 1px solid var(--ai-3); border-radius: 999px; padding: 2px 9px; white-space: nowrap; }
.rung b { font-family: var(--font-display); font-weight: 400; color: var(--kin); margin-left: 3px; }
.rung.pass { color: var(--hai); border-style: dashed; }
.rung.mine { border-color: var(--kinari); }
.ladder .arrow { color: var(--hai); font-size: 11px; }
.prompt { margin: 0; font-weight: 700; font-size: 16px; text-wrap: balance; }
.log { list-style: none; margin: 0; padding: 0; font-size: 12.5px; color: var(--hai); display: grid; gap: 2px; min-height: 0; overflow: hidden; }
.log li:last-child { color: var(--kinari); }
.log.notes li { color: var(--kinari); }
.log.notes li:first-child { color: var(--kin); font-weight: 700; }

/* ---- 自分 ---- */
.me { background: var(--ai-2); border-radius: 16px; padding: 12px; display: grid; gap: 10px; }
.me.active { box-shadow: inset 0 0 0 2px var(--kin); }
.me.target { box-shadow: inset 0 0 0 2px var(--tsubaki); }
.me-head { display: flex; align-items: center; gap: 8px; }
.me-crest { width: 28px; height: 28px; font-size: 14px; }
.me-name { font-weight: 700; flex: 1; }
.me-stack { display: flex; gap: 6px; align-items: center; min-height: calc(var(--disc) + 6px); flex-wrap: wrap; }
.me-stack .label { font-size: 12px; color: var(--hai); }

.controls { display: grid; gap: 8px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.place-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--ai); border: 1.5px solid var(--ai-3); border-radius: 12px;
  padding: 8px; min-height: 56px; cursor: pointer; font-weight: 700;
}
.place-btn .disc { --disc: 36px; }
.place-btn > span { display: grid; text-align: left; line-height: 1.2; font-size: 17px; }
.place-btn small { color: var(--hai); font-weight: 500; font-size: 11.5px; }
.place-btn:disabled { opacity: 0.35; cursor: default; }
.primary, .secondary {
  border: none; border-radius: 12px; min-height: 48px; padding: 0 16px; font-weight: 700; cursor: pointer; font-size: 16px;
}
.primary { background: var(--kin); color: var(--sumi); }
.secondary { background: var(--ai); border: 1.5px solid var(--ai-3); }
.primary:disabled, .secondary:disabled { opacity: 0.35; cursor: default; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.chip {
  width: 48px; height: 48px; border-radius: 50%; border: 2px solid var(--kin); background: none;
  font-family: var(--font-display); font-size: 20px; color: var(--kin); cursor: pointer;
}
.chip:active, .place-btn:active, .primary:active { transform: scale(0.96); }
.hint { margin: 0; font-size: 12.5px; color: var(--hai); text-align: center; }

/* ---- シート ---- */
.sheet {
  position: fixed; inset: 0; background: rgba(8, 12, 26, 0.7); display: grid; place-items: end center; z-index: 20;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.sheet-card { background: var(--ai-2); border-radius: 18px; padding: 18px; width: 100%; max-width: 448px; display: grid; gap: 12px; max-height: 85%; overflow: auto; }
.sheet-card h2 { font-family: var(--font-display); font-weight: 400; margin: 0; font-size: 20px; }
.rules-sub { margin: 4px 0 0; font-size: 14px; }
.tips { margin: 0; display: grid; gap: 8px; }
.tips > div { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; }
.tips dt { display: flex; gap: 2px; }
.tips dd { margin: 0; font-size: 13px; line-height: 1.5; }
.reset-row { display: flex; gap: 8px; flex-wrap: wrap; }
.reset-row button { flex: 1; font-size: 14px; min-height: 40px; }
.danger { border-color: var(--tsubaki); color: var(--tsubaki); }
.rules-list { margin: 0; padding-left: 1.2em; display: grid; gap: 6px; line-height: 1.6; }

.history { display: grid; gap: 10px; }
.h-round { display: grid; gap: 4px; padding-bottom: 10px; border-bottom: 1px dashed var(--ai-3); }
.h-round h3 { margin: 0; font-size: 13px; color: var(--hai); font-weight: 700; }
.h-line { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 13px; }
.h-line .who { min-width: 4.5em; color: var(--hai); }
.mini { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--kinari); }
.mini svg { width: 82%; height: 82%; }
.mini.S { background: var(--sumi); }
.mini-crest { width: 26px; height: 26px; font-size: 14px; border-width: 1.5px; }
.h-tell { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: start; font-size: 13px; line-height: 1.5; }
.h-result { font-size: 13px; font-weight: 700; }
.h-note { font-size: 12px; color: var(--hai); margin: 0; }
.banner { display: grid; gap: 4px; justify-items: center; }
.banner strong { font-family: var(--font-display); font-weight: 400; font-size: clamp(18px, 5.4vw, 24px); text-wrap: balance; line-height: 1.25; }
.banner.good strong { color: var(--kin); }
.banner.bad strong { color: var(--tsubaki); }

@media (max-height: 640px) {
  :root { --disc: 32px; }
  .bid-num { font-size: 36px; }
  .log:not(.notes) li:nth-last-child(n+3) { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
