/* ============================================================
   モルック得点表 — スマホ最優先のスタイル
   ============================================================ */

:root {
  --bg:        #f4f6f4;
  --surface:   #ffffff;
  --surface-2: #eef1ee;
  --text:      #14261d;
  --muted:     #64766c;
  --line:      #dfe5e0;
  --accent:    #0e7c4a;
  --accent-ink:#ffffff;
  --accent-sub:#e3f3ea;
  --warn:      #b45309;
  --warn-bg:   #fdf1dc;
  --danger:    #b42318;
  --danger-bg: #fdeceb;
  --gold:      #b8860b;
  --radius:    16px;
  --shadow:    0 1px 2px rgba(20,38,29,.06), 0 8px 24px rgba(20,38,29,.06);
  --tap:       58px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0b1220;
    --surface:   #131d2e;
    --surface-2: #1b2739;
    --text:      #e8eef5;
    --muted:     #94a4b8;
    --line:      #26344a;
    --accent:    #2bb673;
    --accent-ink:#06231a;
    --accent-sub:#12332a;
    --warn:      #f0b445;
    --warn-bg:   #3a2c14;
    --danger:    #ff8a80;
    --danger-bg: #3a1d1c;
    --gold:      #e3b23c;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP",
               "Yu Gothic UI", "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: .01em; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.view { max-width: 560px; margin: 0 auto; }
.muted { color: var(--muted); }

/* ---------- ボタン ---------- */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 0 18px;
  min-height: 50px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, opacity .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.block { display: block; width: 100%; }
.btn.lg { min-height: var(--tap); font-size: 1.0625rem; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn.miss { background: var(--surface-2); border-color: var(--line); color: var(--text); }

.icon-btn {
  appearance: none; border: 0; background: transparent;
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg {
  width: 22px; height: 22px; fill: none;
  stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.icon-btn svg circle { fill: currentColor; stroke: none; }

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

.home-wrap { padding: max(24px, env(safe-area-inset-top)) 16px 40px; }
.home-head { text-align: center; padding: 16px 0 24px; }
.logo { display: block; margin: 0 auto; }
.home-head h1 { font-size: 1.6rem; margin-top: 8px; }
.lead { color: var(--muted); font-size: .9375rem; margin: 8px 0 0; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 16px;
  margin-bottom: 16px;
}
.card h2 { font-size: 1.0625rem; margin-bottom: 14px; }

.field { display: block; margin-bottom: 16px; }
.field > span {
  display: flex; align-items: baseline; gap: 8px;
  font-size: .8125rem; font-weight: 700; color: var(--muted); margin-bottom: 8px;
}
.field em { font-style: normal; font-weight: 500; opacity: .8; }

input[type="text"] {
  width: 100%;
  min-height: 50px;
  padding: 0 14px;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 12px;
}
input[type="text"]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.name-list { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 8px; }
.name-row { display: flex; gap: 8px; align-items: center; }
.name-row .seat {
  flex: 0 0 26px; text-align: center; font-size: .8125rem;
  font-weight: 700; color: var(--muted);
}
.name-row input { flex: 1 1 auto; }
.name-row .del {
  flex: 0 0 auto; appearance: none; border: 0; background: transparent;
  color: var(--muted); font-size: 1.25rem; width: 38px; height: 38px;
  border-radius: 50%; cursor: pointer;
}
.name-row .del:active { background: var(--surface-2); }

.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1 1 auto; text-transform: uppercase; letter-spacing: .22em; font-weight: 700; }
.join-row .btn { flex: 0 0 92px; width: auto; }

.error { color: var(--danger); font-size: .875rem; margin: 10px 0 0; }
.home-foot { text-align: center; color: var(--muted); font-size: .8125rem; padding: 8px 0; }

/* ---------- 部屋ヘッダ ---------- */

.room-head {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.room-head-main { flex: 1 1 auto; min-width: 0; }
.room-head h1 {
  font-size: 1.0625rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.room-meta { display: flex; align-items: center; gap: 8px; font-size: .75rem; }
.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .16em; font-weight: 700; color: var(--accent);
}
.room-head-actions { display: flex; align-items: center; gap: 2px; }

.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 4px; }
.conn.online { background: var(--accent); }
.conn.offline { background: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.room-body { padding: 14px 12px calc(28px + env(safe-area-inset-bottom)); }

/* ---------- 手番カード ---------- */

.turn-card {
  background: linear-gradient(160deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 72%, #063a24) 100%);
  color: #fff;
  border-radius: 20px;
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.turn-label { font-size: .75rem; opacity: .85; font-weight: 700; letter-spacing: .08em; }
.turn-name {
  font-size: clamp(1.75rem, 9vw, 2.25rem); font-weight: 800; line-height: 1.2;
  margin: 2px 0 12px; word-break: break-word;
}
.turn-stats { display: flex; gap: 8px; }
.turn-stats > div {
  flex: 1 1 0; background: rgba(255,255,255,.16); border-radius: 12px;
  padding: 8px 4px; text-align: center;
}
.turn-stats strong { display: block; font-size: 1.5rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.turn-stats span { font-size: .6875rem; opacity: .85; }

.turn-history { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 12px; min-height: 4px; }
.turn-history .chip { background: rgba(255,255,255,.2); color: #fff; }

/* ---------- キーパッド ---------- */

.keypad-wrap { margin-bottom: 20px; }
.keypad-hint {
  display: flex; flex-direction: column; gap: 2px;
  font-size: .8125rem; font-weight: 700; color: var(--muted);
  margin-bottom: 10px; text-align: center;
}
.keypad-hint em { font-style: normal; font-weight: 500; font-size: .75rem; opacity: .85; }

.keypad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 8px; }
.key {
  appearance: none; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
  border-radius: 14px; min-height: 62px;
  font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums;
  cursor: pointer; box-shadow: var(--shadow);
  transition: transform .07s ease, background .12s ease;
}
.key:active { transform: scale(.94); background: var(--accent-sub); }
.key:disabled { opacity: .35; box-shadow: none; }
/* ちょうど50点になる数字を強調 */
.key.winning { border-color: var(--accent); background: var(--accent-sub); color: var(--accent); }
/* 50点を超えて25点に戻ってしまう数字 */
.key.bust { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); }

.keypad-wrap .btn { margin-bottom: 8px; }

/* ---------- 得点表 ---------- */

.section-title { font-size: .8125rem; color: var(--muted); margin-bottom: 8px; padding-left: 4px; }
.board { margin-bottom: 22px; }

.player-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.player {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
  padding: 12px 14px; cursor: pointer; border: 1.5px solid transparent;
  transition: border-color .15s ease;
}
.player:active { background: var(--surface-2); }
.player.is-turn { border-color: var(--accent); }
.player.is-out { opacity: .55; }
.player.is-winner { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 10%, var(--surface)); }

.player-top { display: flex; align-items: center; gap: 10px; }
.player-name { flex: 1 1 auto; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-score { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.player-remaining { font-size: .75rem; color: var(--muted); width: 46px; text-align: right; }

.badge {
  font-size: .6875rem; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.turn { background: var(--accent-sub); color: var(--accent); }
.badge.out { background: var(--danger-bg); color: var(--danger); }
.badge.win { background: color-mix(in srgb, var(--gold) 22%, transparent); color: var(--gold); }

.bar { height: 6px; border-radius: 999px; background: var(--surface-2); margin: 10px 0 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width .3s ease; }

.player-foot { display: flex; align-items: center; gap: 8px; }
.misses { display: flex; gap: 4px; flex: 0 0 auto; }
.miss-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.miss-dot.on { background: var(--danger); }

.chips { display: flex; gap: 5px; flex: 1 1 auto; overflow: hidden; justify-content: flex-end; }
.chip {
  font-size: .75rem; font-weight: 700; font-variant-numeric: tabular-nums;
  min-width: 26px; text-align: center; padding: 2px 6px; border-radius: 8px;
  background: var(--surface-2); color: var(--text);
}
.chip.zero { color: var(--muted); }
.chip.over { background: var(--warn-bg); color: var(--warn); }
.chip.win  { background: color-mix(in srgb, var(--gold) 22%, transparent); color: var(--gold); }
.chip.out  { background: var(--danger-bg); color: var(--danger); }

/* ---------- ログ ---------- */

.log-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.log-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border-radius: 10px; padding: 9px 12px; font-size: .875rem;
}
.log-round {
  font-size: .75rem; font-weight: 700; color: var(--muted);
  padding: 10px 4px 2px;
}
.log-round:first-child { padding-top: 0; }
.log-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-pts { font-weight: 800; font-variant-numeric: tabular-nums; }
.log-total { flex: 0 0 62px; text-align: right; color: var(--muted); font-size: .75rem; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); font-size: .875rem; text-align: center; padding: 18px; }

/* ---------- オーバーレイ / シート ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(8, 20, 14, .55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  width: 100%; max-width: 560px;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 86vh; overflow-y: auto;
  animation: rise .22s cubic-bezier(.2,.8,.3,1);
}
@keyframes rise { from { transform: translateY(20px); opacity: .6; } }
.sheet h2 { font-size: 1.0625rem; margin-bottom: 14px; }

.sheet-item {
  appearance: none; border: 0; background: transparent; width: 100%;
  text-align: left; padding: 15px 4px; font-weight: 600;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.sheet-item:active { background: var(--surface-2); }
.sheet-item.danger { color: var(--danger); }
.sheet .btn { margin-top: 16px; }

.edit-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.winner-card {
  margin: auto; width: calc(100% - 32px); max-width: 380px;
  background: var(--surface); border-radius: 22px; padding: 28px 20px;
  text-align: center; animation: rise .25s cubic-bezier(.2,.8,.3,1);
}
.winner-emoji { font-size: 56px; line-height: 1; }
.winner-label { color: var(--muted); font-size: .875rem; margin-top: 6px; font-weight: 700; }
.winner-name { font-size: 1.75rem; font-weight: 800; margin: 4px 0 22px; word-break: break-word; }

/* 決着時の最終順位表（勝者カード内） */
.standings { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 4px; text-align: left; }
.standing {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border-radius: 10px; padding: 9px 12px; font-size: .875rem;
}
.standing:first-child { background: color-mix(in srgb, var(--gold) 18%, var(--surface-2)); }
.st-rank { flex: 0 0 34px; font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.standing:first-child .st-rank { color: var(--gold); }
.st-name { flex: 1 1 auto; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-score { flex: 0 0 auto; color: var(--muted); font-size: .75rem; font-variant-numeric: tabular-nums; }

.detail-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 2px; border-bottom: 1px solid var(--line); font-size: .9375rem;
}
.detail-row .n { flex: 0 0 58px; color: var(--muted); font-size: .8125rem; }
.detail-row .pts { flex: 0 0 48px; font-weight: 800; font-variant-numeric: tabular-nums; }
.detail-row .calc { flex: 1 1 auto; color: var(--muted); font-size: .8125rem; font-variant-numeric: tabular-nums; }
.detail-row .tag { font-size: .6875rem; font-weight: 700; }
.detail-row .tag.over { color: var(--warn); }
.detail-row .tag.out { color: var(--danger); }
.detail-row .tag.win { color: var(--gold); }
.detail-sum { display: flex; gap: 8px; margin-bottom: 14px; }
.detail-sum > div { flex: 1 1 0; background: var(--surface-2); border-radius: 12px; padding: 10px; text-align: center; }
.detail-sum strong { display: block; font-size: 1.375rem; font-variant-numeric: tabular-nums; }
.detail-sum span { font-size: .6875rem; color: var(--muted); }

/* ---------- トースト ---------- */

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80; max-width: calc(100% - 32px);
  background: var(--text); color: var(--bg);
  padding: 12px 18px; border-radius: 999px;
  font-size: .875rem; font-weight: 700; text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  animation: toast-in .2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }
.toast.warn   { background: var(--warn);   color: #fff; }
.toast.danger { background: var(--danger); color: #fff; }

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