/* ==========================================================================
   TOKKUROW - GAME LAYOUT (canvas, HUD, controls, overlays)
   Verified current version. No changes needed.
   ========================================================================== */

/* ---------- Canvas ---------- */
#c {
  position: absolute;
  inset: 0;
  display: block;
  touch-action: manipulation;
  max-width: 100%;
  max-height: 100%;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: start;
  gap: var(--sp-2);
  padding:
    calc(var(--sp-2) + var(--safe-top))
    calc(var(--sp-2) + var(--safe-right))
    var(--sp-2)
    calc(var(--sp-2) + var(--safe-left));
  pointer-events: none;
  z-index: var(--z-hud);
}

#hud > * {
  pointer-events: auto;
  min-width: 0;
}

.badge {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  background: linear-gradient(180deg, rgba(30, 22, 14, 0.95), rgba(18, 12, 8, 0.96));
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 220, 160, 0.06);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  transition: all var(--dur-base) var(--ease);
  min-width: 0;
  max-width: 100%;
}

.badge.p1 { justify-self: end; }

.badge.active {
  border-color: var(--gold-2);
  box-shadow: var(--shadow-gold), var(--shadow-md);
  background: linear-gradient(180deg, rgba(50, 36, 20, 0.96), rgba(30, 20, 12, 0.98));
}

.badge.p1.active {
  border-color: var(--blue-2);
  box-shadow: var(--shadow-blue), var(--shadow-md);
  background: linear-gradient(180deg, rgba(30, 42, 60, 0.96), rgba(18, 24, 38, 0.98));
}

.badge.ready {
  border-color: var(--ok);
  box-shadow: 0 0 18px rgba(39, 174, 96, 0.4), var(--shadow-md);
}

.badge .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 8px currentColor;
}

.badge.p0 .dot { background: var(--gold); color: var(--gold); }
.badge.p1 .dot { background: var(--blue); color: var(--blue); }

.badge .info {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
  overflow: hidden;
}

.badge .nm {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  font-size: var(--fs-sm);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.badge.p1 .nm { justify-content: flex-end; }

.badge .nm > span:not([class*="tag"]) {
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.badge .sc {
  font-size: var(--fs-2xs);
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge .first-tag,
.badge .ready-tag {
  font-size: 0.5rem;
  padding: 1px 5px;
  border-radius: 5px;
  font-weight: 800;
  letter-spacing: 0.4px;
  flex-shrink: 0;
  line-height: 1.4;
  display: none;
}

.badge .first-tag {
  color: #1a1410;
  background: linear-gradient(180deg, #f0d28a, #c8a45c);
}

.badge .ready-tag {
  color: #0f2a18;
  background: linear-gradient(180deg, #7fd89a, #4db876);
}

.badge .first-tag.show,
.badge .ready-tag.show { display: inline-block; }

/* ---------- Center info ---------- */
#centerInfo {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-pill);
  background: linear-gradient(180deg, rgba(30, 22, 14, 0.95), rgba(18, 12, 8, 0.96));
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 220, 160, 0.06);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  text-align: center;
  min-width: 0;
  max-width: 40vw;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--dim);
  line-height: 1.25;
  transition: all var(--dur-base) var(--ease);
}

#centerInfo .ci-main {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  transition: color var(--dur-base) var(--ease);
}

#centerInfo .ci-stats {
  display: block;
  font-size: var(--fs-2xs);
  color: var(--dim-2);
  letter-spacing: 0.3px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  max-height: 0;
  opacity: 0;
  transition:
    max-height var(--dur-base) var(--ease),
    opacity var(--dur-base) var(--ease),
    margin-top var(--dur-base) var(--ease);
}

#centerInfo .ci-stats.show {
  max-height: 18px;
  opacity: 1;
  margin-top: 2px;
}

/* ---------- Side stats ---------- */
.sideStats {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  background: linear-gradient(180deg, rgba(30, 22, 14, 0.94), rgba(18, 12, 8, 0.96));
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 220, 160, 0.05);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  min-width: 62px;
  text-align: center;
  pointer-events: none;
  z-index: var(--z-stats);
}

#sideStatsP0 {
  left: calc(var(--sp-1) + var(--safe-left));
  border-color: rgba(232, 193, 112, 0.3);
}

#sideStatsP1 {
  right: calc(var(--sp-1) + var(--safe-right));
  border-color: rgba(127, 184, 232, 0.3);
}

.sideStats .lbl {
  font-size: 0.55rem;
  color: var(--dim);
  letter-spacing: 1.2px;
  text-transform: uppercase;
  margin-bottom: 2px;
  font-weight: 800;
}

.sideStats .big {
  font-size: 1.4rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -0.5px;
}

#sideStatsP0 .big { color: var(--gold); }
#sideStatsP1 .big { color: var(--blue); }

.sideStats .sub {
  font-size: 0.55rem;
  color: var(--dim);
  margin-top: 2px;
  font-weight: 600;
  white-space: nowrap;
}

/* Hide side stats where the board doesn't reserve space for them */
@media (max-width: 560px), (max-height: 480px) {
  .sideStats { display: none; }
}

/* ---------- Controls ---------- */
#controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--sp-1);
  padding:
    var(--sp-2)
    calc(var(--sp-2) + var(--safe-right))
    calc(var(--sp-2) + var(--safe-bottom))
    calc(var(--sp-2) + var(--safe-left));
  pointer-events: none;
  flex-wrap: wrap;
  z-index: var(--z-controls);
}

#controls > * {
  pointer-events: auto;
  flex-shrink: 0;
}

/* ---------- Buttons (base) ---------- */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 40px;
  min-width: 40px;
  padding: 0 var(--sp-4);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(36, 26, 16, 0.96), rgba(22, 15, 9, 0.98));
  color: var(--text);
  font-weight: 600;
  font-size: var(--fs-sm);
  letter-spacing: 0.1px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition:
    background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease);
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 220, 160, 0.05);
  position: relative;
  overflow: hidden;
}

button::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease);
}

button:hover::before { opacity: 1; }

button:hover {
  border-color: var(--gold-2);
  background: linear-gradient(180deg, rgba(50, 36, 20, 0.96), rgba(30, 20, 12, 0.98));
}

button:active { transform: scale(0.96); }

button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

button.primary {
  background: linear-gradient(180deg, #f0d28a 0%, #e8c170 30%, #c8a45c 100%);
  color: #1a1410;
  border-color: var(--gold-2);
  font-weight: 800;
  box-shadow: var(--shadow-gold), var(--shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.15);
}

button.primary:hover {
  background: linear-gradient(180deg, #f8dc94 0%, #f0ce80 30%, #d4af68 100%);
  border-color: var(--gold);
  box-shadow: var(--shadow-gold), 0 8px 24px rgba(232, 193, 112, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

button.danger {
  background: linear-gradient(180deg, rgba(80, 25, 20, 0.9), rgba(50, 16, 12, 0.96));
  border-color: rgba(192, 57, 43, 0.5);
  color: var(--bad-bright);
}

button.danger:hover {
  background: linear-gradient(180deg, rgba(120, 40, 30, 0.9), rgba(70, 22, 16, 0.96));
  border-color: var(--bad);
}

button.on {
  background: linear-gradient(180deg, rgba(30, 80, 45, 0.85), rgba(18, 50, 28, 0.95));
  border-color: rgba(39, 174, 96, 0.5);
  color: var(--ok-bright);
  box-shadow: 0 0 16px rgba(39, 174, 96, 0.25), var(--shadow-sm);
}

button.icon-only {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
}

svg.icn {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Toast ---------- */
#toast {
  position: absolute;
  top: calc(66px + var(--safe-top));
  left: 50%;
  transform: translate(-50%, -12px);
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-pill);
  background: linear-gradient(180deg, rgba(20, 14, 8, 0.98), rgba(10, 7, 4, 0.98));
  border: 1px solid var(--border-hover);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 220, 160, 0.08);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text);
  text-align: center;
  max-width: min(86vw, 420px);
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  z-index: var(--z-toast);
  transition: opacity var(--dur-base) var(--ease), transform var(--dur-base) var(--ease-out);
  overflow-wrap: break-word;
  word-wrap: break-word;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Kickoff overlay ---------- */
#kickoffOverlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: var(--z-kickoff);
  display: flex;
  align-items: center;
  justify-content: center;
}

#kickoffOverlay.hidden { display: none; }

.kickoff-center {
  position: relative;
  width: min(180px, 44vw);
  height: min(180px, 44vw);
  display: flex;
  align-items: center;
  justify-content: center;
}

.kickoff-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.kickoff-ring circle {
  fill: none;
  stroke-width: 6;
}

.kickoff-ring .bg { stroke: rgba(200, 164, 92, 0.15); }

.kickoff-ring .fg {
  stroke: var(--gold);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.1s linear;
  filter: drop-shadow(0 0 12px rgba(232, 193, 112, 0.6));
}

.kickoff-num {
  font-size: clamp(2.8rem, 8vw, 4.2rem);
  font-weight: 900;
  color: var(--gold);
  text-shadow:
    0 0 30px rgba(232, 193, 112, 0.7),
    0 0 60px rgba(232, 193, 112, 0.4),
    0 2px 4px rgba(0, 0, 0, 0.6);
  animation: pulseNum 1s ease-in-out infinite;
  font-variant-numeric: tabular-nums;
}

@keyframes pulseNum {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.12); }
}

.kickoff-label {
  position: absolute;
  top: calc(100% + var(--sp-6));
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--text);
  padding: var(--sp-2) var(--sp-4);
  background: linear-gradient(180deg, rgba(20, 14, 8, 0.95), rgba(10, 7, 4, 0.95));
  border: 1px solid var(--border-hover);
  border-radius: var(--r-pill);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  text-align: center;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kickoff-label .hint {
  display: block;
  font-size: var(--fs-2xs);
  color: var(--dim);
  margin-top: 2px;
  font-weight: 500;
}

.kickoff-begin {
  position: fixed;
  top: calc(50% + min(140px, 34vw));
  left: 50%;
  transform: translateX(-50%);
  min-height: 48px;
  padding: var(--sp-3) var(--sp-6);
  font-size: var(--fs-md);
  font-weight: 800;
  letter-spacing: 0.4px;
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, #f0d28a, #e8c170 40%, #c8a45c);
  color: #1a1410;
  border: 2px solid var(--gold);
  box-shadow: 0 8px 28px rgba(232, 193, 112, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  pointer-events: auto;
  z-index: calc(var(--z-kickoff) + 1);
  display: none;
  font-family: var(--font);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.2);
  animation: kickoffPulse 1.6s ease-in-out infinite;
  white-space: nowrap;
  max-width: calc(100vw - var(--sp-4));
}

.kickoff-begin.show {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
}

@keyframes kickoffPulse {
  0%, 100% {
    transform: translateX(-50%) scale(1);
    box-shadow: 0 8px 28px rgba(232, 193, 112, 0.5);
  }
  50% {
    transform: translateX(-50%) scale(1.05);
    box-shadow: 0 12px 36px rgba(232, 193, 112, 0.75);
  }
}

/* ---------- Watermark ---------- */
#watermark {
  position: absolute;
  bottom: calc(56px + var(--safe-bottom));
  right: calc(var(--sp-2) + var(--safe-right));
  font-size: var(--fs-2xs);
  color: rgba(200, 164, 92, 0.45);
  font-weight: 600;
  letter-spacing: 0.4px;
  pointer-events: none;
  z-index: 3;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  max-width: calc(100% - var(--sp-4));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .badge { padding: 6px 10px; gap: 6px; }
  .badge .nm { font-size: 0.72rem; }
  .badge .sc { font-size: 0.58rem; }
  #centerInfo {
    font-size: 0.70rem;
    padding: 6px 12px;
    max-width: 42vw;
  }
  #centerInfo .ci-stats { font-size: 0.55rem; }
  #controls button {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
  }
  svg.icn { width: 14px; height: 14px; }
  #toast {
    top: calc(56px + var(--safe-top));
    font-size: 0.75rem;
    padding: 8px 16px;
  }
  #watermark { font-size: 0.5rem; }
}

@media (max-width: 360px) {
  #centerInfo { padding: 4px 8px; font-size: 0.65rem; }
  .badge { padding: 4px 8px; }
  .badge .dot { width: 8px; height: 8px; }
  #controls button { width: 32px; height: 32px; min-width: 32px; min-height: 32px; }
  svg.icn { width: 13px; height: 13px; }
}

@media (max-height: 520px) {
  #toast { top: calc(56px + var(--safe-top)); padding: 6px 14px; font-size: 0.72rem; }
  .kickoff-center { width: 120px; height: 120px; }
  .kickoff-num { font-size: 2.4rem; }
  .kickoff-begin { top: calc(50% + 100px); padding: 10px 20px; font-size: 0.82rem; }
  .kickoff-label { top: calc(100% + 16px); font-size: 0.72rem; padding: 6px 12px; }
  #watermark { bottom: calc(44px + var(--safe-bottom)); }
}
/* ============================================================
   v8 additions — per-side clocks, match label, kickoff prompt
   (no board geometry is touched here)
   ============================================================ */
.badge .turn-clock {
  display: block;
  min-height: 1.15em;              /* reserved so badges never change height */
  font-size: var(--fs-2xs);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: .06em;
  color: var(--dim);
  white-space: nowrap;
}
.badge.p1 .turn-clock { text-align: right; }
.badge .turn-clock.active { color: #f2d9a8; }
.badge .turn-clock.low { color: #ff7a6b; animation: turnTimerPulse 1.1s ease-in-out infinite; }
@keyframes turnTimerPulse { 0%, 100% { opacity: 1; } 50% { opacity: .65; } }

#centerInfo .ci-match {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--dim-2);
}
#centerInfo .ci-match:empty { display: none; }

.badge .nm > span:not([class*="tag"]) { max-width: 18ch; }
@media (min-width: 700px) { .badge .nm > span:not([class*="tag"]) { max-width: 26ch; } }

.sideStats { min-width: 66px; max-width: 84px; }
.sideStats .sub { overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }

/* Kickoff: paused-on-timeout prompt. Overlay stays pointer-events:none so
   the board underneath remains clickable while the prompt is shown. */
#kickoffOverlay.expired .kickoff-num { color: #ff9d6b; animation: turnTimerPulse 1s ease-in-out infinite; }
#kickoffOverlay.expired .kickoff-label .hint {
  display: block;
  white-space: normal;
  max-width: min(86vw, 360px);
  margin: 6px auto 0;
  font-size: .9rem;
  font-weight: 800;
  color: #ffd9a0;
  line-height: 1.3;
}
