:root {
  color-scheme: light;
  --ink: #1e2a3d;
  --muted: #6f7890;
  --line: #dfe6f2;
  --bg: #f4f8ff;
  --card: #ffffff;
  --blue: #2f6fd0;
  --blue-soft: #e7f0ff;
  --green: #1f9d6b;
  --orange: #e8760f;
  --danger: #d8453f;
  --shadow: 0 10px 28px rgba(60, 85, 125, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 640px);
  margin: 0 auto;
  padding: 14px 14px 40px;
}

/* ---------- ヘッダー ---------- */

.hero {
  padding: 8px 4px 14px;
}

.hero h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}

.catch {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.room-chip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 0.82rem;
  color: var(--muted);
}

#room-code-label {
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.08em;
}

.chip-button {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 700;
}

.demo-banner {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff6e5;
  border: 1px solid #ffd79a;
  color: #8a5200;
  font-size: 0.82rem;
  line-height: 1.6;
}

/* ---------- パネル ---------- */

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.section-block {
  margin-bottom: 14px;
  padding: 16px;
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.section-block h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.lead,
.notice {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.7;
}

.notice {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: #fff6e5;
  color: #8a5200;
  font-size: 0.8rem;
}

.field {
  display: block;
  margin-bottom: 12px;
}

.field span {
  display: block;
  margin-bottom: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.field input,
.field select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
}

.field input:focus,
.field select:focus {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

#join-code {
  letter-spacing: 0.24em;
  text-transform: uppercase;
  font-weight: 700;
}

.primary-button,
.secondary-button,
.danger-button {
  width: 100%;
  padding: 13px 16px;
  border-radius: 12px;
  font-weight: 700;
}

.primary-button {
  background: var(--blue);
  color: #fff;
}

.secondary-button {
  margin-bottom: 8px;
  background: var(--blue-soft);
  color: var(--blue);
}

.danger-button {
  background: #ffeceb;
  color: var(--danger);
}

.recent-rooms {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.recent-rooms button {
  padding: 6px 12px;
  border-radius: 999px;
  background: #eef2f9;
  color: var(--ink);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
}

/* ---------- スコアボード ---------- */

.status-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 0 4px 8px;
}

.status-main {
  font-size: 1.05rem;
  font-weight: 800;
}

.status-outs {
  font-size: 0.9rem;
  color: var(--muted);
  letter-spacing: 0.1em;
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 6px;
  padding: 18px 12px;
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.team-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.team-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}

.team-runs {
  font-size: 3.4rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.team-flag {
  min-height: 1.2em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--orange);
}

.team-score.batting .team-name,
.team-score.batting .team-runs {
  color: var(--blue);
}

.score-sep {
  font-size: 1.6rem;
  color: var(--line);
}

/* イニング別スコア */

.linescore-wrap {
  margin: 12px 0 14px;
  overflow-x: auto;
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.linescore {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.linescore th,
.linescore td {
  padding: 8px 4px;
  min-width: 1.85rem;
  text-align: center;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.linescore thead th {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.linescore th.row-head {
  position: sticky;
  left: 0;
  background: var(--card);
  text-align: left;
  padding-left: 10px;
  min-width: 4.8rem;
  max-width: 4.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.8rem;
}

/* 回数が多くて横にはみ出しても、合計だけは常に右端に見えるようにする */
.linescore td.total,
.linescore thead th:last-child {
  position: sticky;
  right: 0;
  background: #f2f6fd;
  box-shadow: -6px 0 6px -6px rgba(60, 85, 125, 0.25);
}

.linescore td.total {
  font-weight: 800;
}

.linescore td.now {
  background: var(--blue-soft);
  border-radius: 6px;
  font-weight: 800;
}

/* 記録パネル */

.recording-side {
  margin: 0 0 10px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--blue);
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.run-button,
.out-button {
  padding: 15px 4px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 800;
  background: var(--blue);
  color: #fff;
}

.run-button.undo,
.out-button.subtle {
  background: #eef2f9;
  color: var(--muted);
}

.out-button {
  background: var(--green);
  font-size: 0.78rem;
}

/* タップで選ぶメモ */

.field-label {
  margin: 14px 0 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-grid button {
  padding: 11px 14px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 0.88rem;
  font-weight: 700;
}

.chip-grid button:active {
  background: var(--blue);
  color: #fff;
}

.chip-grid.small button {
  padding: 7px 12px;
  background: #eef2f9;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.memo-free {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.memo-free summary {
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
}

.memo-free .field {
  margin-top: 10px;
}

/* メモ一覧 */

.memo-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.memo-list li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.87rem;
  line-height: 1.6;
}

.memo-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.memo-remove {
  flex: none;
  align-self: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: #ffeceb;
  color: var(--danger);
  font-size: 0.76rem;
  font-weight: 700;
}

.memo-remove:disabled {
  opacity: 0.5;
}

.memo-list li:last-child {
  border-bottom: 0;
}

.memo-when {
  display: inline-block;
  margin-right: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2f9;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.memo-empty {
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- 共通 ---------- */

.hidden {
  display: none !important;
}

.footer-links {
  margin: 18px 0 0;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
}

.footer-links a {
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: 90vw;
  padding: 11px 18px;
  border-radius: 999px;
  background: rgba(30, 42, 61, 0.94);
  color: #fff;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  z-index: 20;
}

/* 文章ページ（プライバシー・規約） */

.text-page .section-block p,
.text-page .section-block li {
  font-size: 0.88rem;
  line-height: 1.8;
}

.text-list {
  margin: 0;
  padding-left: 1.2em;
  color: var(--muted);
}

.notice-block {
  border: 1px solid #ffd79a;
  background: #fff9ef;
}

.updated-at,
.quick-links {
  font-size: 0.8rem;
  color: var(--muted);
}

.quick-links a {
  margin-right: 12px;
}

/* Baseball theme: scoped so legal pages keep their original appearance. */
.baseball-app {
  --ink: #203d32;
  --muted: #607268;
  --line: #dce5d9;
  --bg: #f5f6ee;
  --blue: #236247;
  --blue-soft: #e8f1e5;
  --green: #377b55;
  --shadow: 0 6px 22px rgba(35, 65, 40, .07);
  background: radial-gradient(ellipse at top, #e6eddd, transparent 520px), var(--bg);
}
.baseball-app .hero { padding: 10px 4px 20px; }
.hero-brand { display: flex; align-items: center; gap: 14px; }
.baseball-mark { flex: 0 0 auto; }
.eyebrow { margin: 0 0 6px; color: #526b42; font-size: .73rem; font-weight: 700; letter-spacing: .08em; }
.baseball-app .hero h1 { font-size: 1.55rem; }
.baseball-app .catch { margin-top: 10px; font-size: .85rem; }
.baseball-app .section-block { border: 1px solid var(--line); }
.baseball-app .section-block h2 { display: flex; align-items: center; gap: 8px; }
.heading-ball { flex: 0 0 auto; }
.baseball-app .lobby .section-block:first-child { border-top: 4px solid #377b55; }
.baseball-app .primary-button { margin-top: 14px; box-shadow: 0 3px 0 #174d35; }
.baseball-app button:focus-visible { outline: 3px solid #c67c20; outline-offset: 3px; }
.baseball-app .scoreboard {
  position: relative;
  overflow: hidden;
  padding: 26px 12px;
  border: 3px solid #c4b889;
  background: repeating-linear-gradient(90deg, transparent 0 39px, rgba(255,255,255,.025) 39px 40px), #1c4335;
  color: #fffdf0;
}
.baseball-app .scoreboard .team-name { color: #e0eadd; }
.baseball-app .scoreboard .team-runs { margin: 8px 0; font-size: 3.8rem; }
.baseball-app .scoreboard .batting .team-runs { color: #ffe4a0; }
.baseball-app .scoreboard .batting .team-name { color: #ffe4a0; }
.baseball-app .team-flag { color: #ffe4a0; }
.baseball-app .team-flag:not(:empty)::before {
  content: "";
  display: inline-block;
  width: 18px; height: 18px;
  margin-right: 5px;
  vertical-align: -4px;
  background: url("ball.svg") center / contain no-repeat;
}
.field-diamond {
  display: block; width: 26px; height: 26px;
  transform: rotate(45deg);
  border: 1px solid #b6cba6;
  background: #477651;
  box-shadow: 3px 3px 0 rgba(0,0,0,.12);
}
.field-diamond::before, .field-diamond::after {
  content: ""; position: absolute; width: 5px; height: 5px; background: #fff8dc;
}
.field-diamond::before { left: -3px; top: -3px; box-shadow: 24px 24px #fff8dc; }
.field-diamond::after { right: -3px; top: -3px; box-shadow: -24px 24px #fff8dc; }
.baseball-app .status-bar { padding: 4px 4px 12px; }
.baseball-app .linescore thead { background: #edf2e7; }
.baseball-app .linescore td.total, .baseball-app .linescore thead th:last-child { background: #e8efdf; }
@media (max-width: 380px) {
  .baseball-mark { width: 68px; height: 68px; }
  .hero-brand { gap: 10px; }
  .baseball-app .hero h1 { font-size: 1.3rem; }
  .eyebrow { font-size: .65rem; }
}
/* Runner occupancy and recorder controls */
.runner-field { position: relative; width: 92px; height: 94px; }
.runner-field::before { content: ''; position: absolute; width: 46px; height: 46px; left: 22px; top: 23px; border: 1px solid #96b092; transform: rotate(45deg); }
.base-marker { position: absolute; display: grid; place-items: center; min-width: 35px; min-height: 30px; border: 1px solid #b8ccac; border-radius: 6px; background: #294e3a; color: #edf4e6; font-size: .72rem; font-weight: 700; }
.base-first { right: 0; top: 33px; }
.base-second { left: 29px; top: 0; }
.base-third { left: 0; top: 33px; }
.base-marker.occupied { background: #ffe29b; color: #3e361d; border-color: #ffe29b; }
.home-marker { position: absolute; top: 73px; left: 33px; font-size: .62rem; color: #d6e4cd; }
.runner-summary { text-align: center; font-size: .85rem; font-weight: 700; margin: 9px 0; }
.runner-controls { padding: 12px 0; border-top: 1px solid var(--line); }
.runner-controls .field-label { margin-top: 0; }
.field-hint { font-weight: 400; font-size: .74rem; }
.base-buttons, .tools-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; }
.base-buttons button { min-height: 48px; border: 1px solid #9cab9b; border-radius: 10px; color: var(--ink); background: #f4f7ef; font-size: .83rem; font-weight: 700; }
.base-buttons button[aria-pressed="true"] { background: #ffe29b; border: 2px solid #806124; color: #493910; }
.clear-bases { background: transparent; color: var(--blue); font-size: .78rem; min-height: 44px; text-decoration: underline; padding: 8px 0; }
.control-help { font-size: .76rem; line-height: 1.65; color: var(--muted); margin: 4px 0 10px; }
.record-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; }
.record-actions .secondary-button { margin: 0; font-size: .82rem; padding: 12px 6px; }
.save-status { margin: 0; min-height: 1.5em; color: var(--blue); font-size: .78rem; }
.match-tools { padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.match-tools summary { cursor: pointer; font-size: .8rem; font-weight: 700; color: var(--muted); padding: 6px 0; }
.tools-grid { margin-top: 10px; }
.baseball-app button:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
@media (max-width: 380px) {
  .runner-field { width: 80px; }
  .runner-field::before { left: 16px; }
  .base-second { left: 23px; }
  .home-marker { left: 27px; }
}

.player-label-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#surname-notice { margin: 0 0 10px; }
