:root {
  --ink: #403a36;
  --muted: #786f69;
  --paper: #fffdf8;
  --cream: #fff7e8;
  --peach: #ffdcca;
  --pink: #ffe4ec;
  --mint: #dcf3e8;
  --sky: #dfeeff;
  --yellow: #fff1a8;
  --line: #5a514b;
  --shadow: 0 7px 0 rgba(90,81,75,.12);
  --radius: 24px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { min-height: 100%; background: var(--cream); }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh; color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgba(255,220,202,.75), transparent 34%),
    radial-gradient(circle at 94% 12%, rgba(220,243,232,.82), transparent 28%),
    linear-gradient(180deg, #fffaf0, #fff7e8 62%, #fffaf2);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  overscroll-behavior-y: none;
}
button, input { font: inherit; }
button { color: inherit; touch-action: manipulation; }
input { color: var(--ink); }
.hidden { display: none !important; }
.background-dots {
  position: fixed; inset: 0; pointer-events: none; opacity: .20;
  background-image: radial-gradient(rgba(90,81,75,.34) 1px, transparent 1px);
  background-size: 18px 18px; mask-image: linear-gradient(to bottom, #000, transparent 65%);
}
.app-shell { position: relative; width: min(100%, 560px); margin: 0 auto; padding: 18px 14px calc(34px + var(--safe-bottom)); }
.app-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 8px 4px 17px; }
.brand-block { min-width: 0; padding-top: 2px; }
.app-header h1 { margin: 0; font-size: clamp(25px, 7vw, 36px); line-height: 1.05; letter-spacing: .03em; font-weight: 950; text-shadow: 0 3px 0 #fff; white-space: nowrap; }
.presents { margin: 7px 0 0 3px; color: var(--muted); font-size: 10px; letter-spacing: .04em; }
.presents a {
  color: inherit;
  font-weight: 900;
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}
.presents a:focus-visible {
  outline: 3px solid rgba(255, 241, 168, .9);
  outline-offset: 3px;
  border-radius: 4px;
}
.header-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 7px; flex: none; }
.header-link-row { display: flex; align-items: center; gap: 6px; }
.header-link-button, .share-button {
  border: 2px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.9);
  min-height: 34px; padding: 5px 9px; font-size: 10px; font-weight: 900; cursor: pointer;
  box-shadow: 0 3px 0 rgba(90,81,75,.12);
}
.header-link-button:first-child { background: var(--pink); }
.header-link-button:last-child { background: var(--sky); }
.screen { display: grid; gap: 14px; }
.card {
  position: relative; overflow: hidden; padding: 18px; border: 2px solid var(--line); border-radius: var(--radius);
  background: rgba(255,253,248,.95); box-shadow: var(--shadow);
}
.card::after { content: ""; position: absolute; width: 78px; height: 78px; right: -33px; top: -38px; border: 2px solid rgba(90,81,75,.11); border-radius: 50%; pointer-events: none; }
.teams-card { background: linear-gradient(155deg, rgba(255,255,255,.97), rgba(255,232,238,.82)); }
.scoreboard-card { background: linear-gradient(145deg, #f9fcff, #eaf5ff); }
.input-card { background: linear-gradient(145deg, #fff, #f1fff8); }
.centered-card { text-align: center; padding-block: 35px; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.section-heading.compact { align-items: center; }
.section-heading h2 { margin: 0; font-size: 20px; line-height: 1.35; }
.eyebrow { margin: 0 0 3px; color: var(--muted); font-size: 11px; font-weight: 900; letter-spacing: .07em; }
.mini-badge, .status-badge {
  display: inline-flex; align-items: center; justify-content: center; min-height: 30px; padding: 4px 10px;
  border: 2px solid var(--line); border-radius: 999px; background: var(--yellow); font-size: 11px; font-weight: 950;
}
.teams-editor { display: grid; gap: 12px; margin: 15px 0 13px; }
.team-editor { padding: 13px; border: 2px solid rgba(90,81,75,.30); border-radius: 20px; background: rgba(255,255,255,.82); }
.team-editor:nth-child(3n+2) { background: rgba(223,238,255,.60); }
.team-editor:nth-child(3n) { background: rgba(220,243,232,.62); }
.team-editor-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; }
.team-number { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border: 2px solid var(--line); border-radius: 50%; background: var(--yellow); font-size: 12px; font-weight: 950; }
.team-name-input, .player-name-input {
  width: 100%; min-width: 0; height: 44px; padding: 8px 11px; border: 2px solid rgba(90,81,75,.30); border-radius: 14px; background: #fff; outline: none; font-weight: 850;
}
.team-name-input:focus, .player-name-input:focus { border-color: var(--line); box-shadow: 0 0 0 4px rgba(255,241,168,.72); }
.players-list { display: grid; gap: 8px; margin-top: 10px; padding-left: 23px; }
.player-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; }
.player-index { color: var(--muted); font-size: 11px; font-weight: 900; }
.icon-button {
  width: 42px; height: 42px; display: inline-flex; align-items: center; justify-content: center; flex: none;
  border: 2px solid var(--line); border-radius: 50%; background: #fff; font-weight: 950; cursor: pointer;
}
.language-button { background: var(--mint); font-size: 12px; }
.text-button { border: 0; background: transparent; padding: 8px; color: var(--ink); font-size: 12px; font-weight: 950; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; cursor: pointer; }
.primary-button, .secondary-button {
  min-height: 54px; padding: 12px 16px; border: 2px solid var(--line); border-radius: 18px; font-weight: 950; cursor: pointer; box-shadow: 0 5px 0 rgba(90,81,75,.17);
}
.primary-button { display: flex; align-items: center; justify-content: center; gap: 10px; background: var(--yellow); }
.secondary-button { background: #fff; }
.full-width { width: 100%; }
.sticky-action { position: sticky; z-index: 5; bottom: calc(10px + var(--safe-bottom)); width: 100%; background: linear-gradient(135deg, #fff0a4, #ffdcae); font-size: 17px; }
button:disabled { opacity: .42; cursor: not-allowed; transform: none !important; box-shadow: none; }
button:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.error-notice { padding: 13px 15px; border: 2px solid #9b514b; border-radius: 16px; background: #fff0ef; color: #743d38; font-size: 13px; font-weight: 800; line-height: 1.55; }
.connection-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 3px; }
.connection-bar > div { display: flex; align-items: center; gap: 7px; min-width: 0; }
.status-badge { background: var(--mint); font-size: 10px; white-space: nowrap; }
.room-code { color: var(--muted); font-size: 10px; font-weight: 850; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-button { background: var(--pink); min-width: 66px; font-size: 12px; }
.winner-banner { display: flex; align-items: center; justify-content: center; gap: 15px; padding: 13px; border: 2px solid var(--line); border-radius: 20px; background: linear-gradient(135deg, var(--yellow), var(--pink)); box-shadow: var(--shadow); text-align: center; }
.winner-banner small { display: block; color: var(--muted); font-size: 10px; font-weight: 900; }
.winner-banner strong { display: block; margin-top: 2px; font-size: 20px; }
.scoreboard { display: grid; gap: 8px; margin-top: 13px; }
.score-row { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 10px; min-height: 57px; padding: 8px 10px 8px 12px; border: 2px solid rgba(90,81,75,.22); border-radius: 17px; background: rgba(255,255,255,.83); }
.score-row.active { border-color: var(--line); background: #fff9d9; box-shadow: 0 4px 0 rgba(90,81,75,.11); }
.score-row.eliminated { opacity: .57; filter: grayscale(.45); }
.score-team-wrap { min-width: 0; }
.score-team-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 950; }
.score-subline { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 3px; color: var(--muted); font-size: 10px; font-weight: 850; }
.miss-chip { display: inline-flex; gap: 3px; }
.miss-dot { width: 8px; height: 8px; border: 1.5px solid var(--line); border-radius: 50%; background: #fff; }
.miss-dot.on { background: #ffaaa1; }
.score-value { display: flex; align-items: baseline; gap: 2px; font-size: 28px; font-weight: 950; }
.score-value small { color: var(--muted); font-size: 10px; }
.sync-status { min-height: 16px; margin: 9px 0 0; color: var(--muted); font-size: 10px; text-align: right; }
.score-pad { display: grid; grid-template-columns: repeat(4,1fr); gap: 9px; margin-top: 14px; }
.score-button { min-height: 58px; border: 2px solid var(--line); border-radius: 17px; background: #fff; font-size: 20px; font-weight: 950; box-shadow: 0 4px 0 rgba(90,81,75,.14); cursor: pointer; }
.score-button:nth-child(4n+1) { background: #fff4dc; }
.score-button:nth-child(4n+2) { background: #eaf7f0; }
.score-button:nth-child(4n+3) { background: #eaf3ff; }
.score-button:nth-child(4n) { background: #ffeaf0; }
.game-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.danger-lite { background: #fff0f0; }
.danger-button { background: #ffb5ad; }
.ended-panel { text-align: center; background: linear-gradient(145deg, #fff, #fff4dc); }
.ended-panel h2 { margin: 0 0 5px; }
.ended-panel p { margin: 0 0 15px; color: var(--muted); }
.stack-actions { display: grid; gap: 10px; margin-top: 17px; }
.loading-spinner { width: 38px; height: 38px; margin: 0 auto 15px; border: 4px solid rgba(90,81,75,.18); border-top-color: var(--line); border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; z-index: 60; left: 50%; bottom: calc(18px + var(--safe-bottom)); transform: translateX(-50%); width: min(calc(100% - 28px),520px); padding: 13px 16px; border: 2px solid var(--line); border-radius: 16px; background: #403a36; color: #fff; box-shadow: 0 7px 0 rgba(0,0,0,.14); text-align: center; font-size: 13px; font-weight: 850; }
.modal { position: fixed; z-index: 50; inset: 0; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(55,48,44,.40); backdrop-filter: blur(3px); }
.modal-sheet { position: relative; width: min(100%,560px); max-height: 92dvh; overflow-y: auto; padding: 12px 18px calc(22px + var(--safe-bottom)); border: 2px solid var(--line); border-bottom: 0; border-radius: 28px 28px 0 0; background: var(--paper); box-shadow: 0 -10px 40px rgba(55,48,44,.18); }
.tall-sheet { min-height: 55dvh; }
.modal-handle { width: 42px; height: 5px; margin: 0 auto 14px; border-radius: 99px; background: rgba(90,81,75,.25); }
.modal-sheet h2 { margin: 6px 0; }
.modal-copy, .helper-text { color: var(--muted); font-size: 13px; line-height: 1.65; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.feature-list { display: grid; gap: 14px; margin: 18px 0 7px; padding-left: 1.4em; }
.feature-list li { padding-left: 3px; line-height: 1.75; font-size: 14px; font-weight: 750; }
.pin-board { margin: 18px auto 4px; width: min(100%,330px); padding: 18px 10px 12px; border: 2px dashed rgba(90,81,75,.38); border-radius: 30px; background: linear-gradient(180deg,var(--sky),#f8fcff); }
.pin-row { display: flex; justify-content: center; gap: 5px; margin-top: -4px; }
.pin { width: clamp(42px,12vw,54px); aspect-ratio: 1/.92; display: inline-flex; align-items: center; justify-content: center; border: 2px solid var(--line); border-radius: 50% 50% 44% 44%; background: #fff7d8; box-shadow: 0 4px 0 rgba(90,81,75,.15); font-size: 17px; font-weight: 950; }
.row-third .pin { background: #ffe2d2; }
.row-second .pin { background: #e6f6ed; }
.throw-line { display: flex; justify-content: center; align-items: center; gap: 7px; margin: 14px auto 0; width: 120px; padding-top: 8px; border-top: 3px solid var(--line); color: var(--muted); font-size: 12px; font-weight: 850; }
.live-players-editor { display: grid; gap: 12px; margin: 15px 0; }
.live-team-card { padding: 13px; border: 2px solid rgba(90,81,75,.28); border-radius: 18px; background: #f9fcff; }
.live-team-card h3 { margin: 0 0 10px; font-size: 16px; }
.winner-sheet { text-align: center; background: radial-gradient(circle at 18% 18%,rgba(255,227,235,.85),transparent 28%), radial-gradient(circle at 82% 15%,rgba(220,243,232,.9),transparent 28%), var(--paper); }
.celebration { margin: 10px 0 12px; font-size: 27px; letter-spacing: .1em; }
.winner-name { margin: 14px 0 4px; font-size: 30px; font-weight: 950; }
@media (max-width: 380px) {
  .app-header h1 { font-size: 23px; }
  .header-link-button { padding-inline: 7px; font-size: 9px; }
  .app-shell { padding-inline: 10px; }
  .card { padding: 15px; }
}
@media (min-width: 480px) { .app-shell { padding-inline: 20px; } .card { padding: 21px; } .score-pad { gap: 11px; } }
@media (display-mode: standalone) { .app-shell { padding-top: calc(18px + env(safe-area-inset-top,0px)); } }

/* v2.5: compact game controls, score layout, and team-order editor */
.scoreboard-heading { align-items: flex-start; flex-wrap: wrap; }
.scoreboard-heading > h2 { flex: 1 1 150px; min-width: 0; }
.scoreboard-tools { display: flex; align-items: center; justify-content: flex-end; gap: 3px; margin-left: auto; }
.scoreboard-tool-button { padding: 6px 4px; font-size: 10px; white-space: nowrap; }
.input-card .section-heading h2 { font-size: 20px; }
.miss-score-button { grid-column: 2 / span 2; background: #fff0f0 !important; font-size: 27px; }
.team-order-editor { display: grid; gap: 9px; margin: 16px 0; }
.team-order-row { display: grid; grid-template-columns: auto minmax(0,1fr) auto; align-items: center; gap: 10px; min-height: 58px; padding: 9px 10px; border: 2px solid rgba(90,81,75,.25); border-radius: 17px; background: #f9fcff; }
.team-order-position { display: inline-flex; align-items: center; justify-content: center; width: 31px; height: 31px; border: 2px solid var(--line); border-radius: 50%; background: var(--yellow); font-size: 12px; font-weight: 950; }
.team-order-info { min-width: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.team-order-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.current-turn-badge { display: inline-flex; align-items: center; min-height: 22px; padding: 2px 7px; border-radius: 999px; background: var(--mint); border: 1.5px solid var(--line); font-size: 9px; font-weight: 900; }
.team-order-controls { display: flex; gap: 5px; }
.order-arrow-button { width: 39px; height: 39px; border: 2px solid var(--line); border-radius: 12px; background: #fff; font-size: 18px; font-weight: 950; box-shadow: 0 3px 0 rgba(90,81,75,.12); cursor: pointer; }
.order-arrow-button:disabled { opacity: .28; }

@media (max-width: 420px) {
  .scoreboard-heading > h2 { flex-basis: 100%; }
  .scoreboard-tools { width: 100%; margin-left: 0; justify-content: flex-end; }
}


/* v2.7: reset saved setup entries */
.reset-setup-button {
  display: block;
  margin: 14px auto 0;
  padding: 7px 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 4px;
  cursor: pointer;
}
.reset-setup-button:active {
  transform: none;
  opacity: .65;
}
