* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  margin: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #111;
  color: #eee;
}

.view {
  /* dvh = the visible viewport; 100vh is taller than the visible area while
     mobile browser toolbars are showing, which hid the bottom of the screen. */
  height: 100vh;
  height: 100dvh;
  width: 100%;
}

.hidden {
  display: none !important;
}

/* --- Setup view --- */

#setup-view {
  overflow-y: auto;
  padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    calc(48px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.wake-tip {
  margin-bottom: 24px;
  padding: 14px 16px;
  border-radius: 12px;
  background: #3a2f0b;
  border: 1px solid #806a1a;
  font-size: 0.9rem;
  line-height: 1.4;
}

.wake-tip p {
  margin: 0 0 8px;
}

.wake-tip button {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid #806a1a;
  background: #262626;
  color: #eee;
  font-size: 0.95rem;
}

.setup {
  max-width: 480px;
  margin: 0 auto;
}

.setup h1 {
  text-align: center;
  margin-bottom: 24px;
}

.team-setup {
  margin-bottom: 28px;
  padding: 16px;
  border: 1px solid #333;
  border-radius: 12px;
}

.team-setup h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.saved-teams {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  min-height: 1px;
}

.saved-team-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 20px;
  border: 2px solid transparent;
  cursor: pointer;
  font-size: 0.95rem;
}

.saved-team-chip.selected {
  border-color: #fff;
}

.saved-team-chip .swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.6);
  flex-shrink: 0;
}

.saved-team-chip .delete-chip,
.saved-team-chip .edit-chip {
  margin-left: 4px;
  opacity: 0.6;
  font-weight: bold;
  padding: 0 4px;
}

.new-team {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.swatch-label {
  font-size: 0.8rem;
  opacity: 0.7;
  margin-top: 2px;
}

.team-name-input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #444;
  background: #1b1b1b;
  color: #eee;
  font-size: 1rem;
}

.color-swatches {
  display: flex;
  gap: 8px;
}

.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}

.color-swatch.selected {
  border-color: #fff;
}

.color-swatch.none-swatch {
  background: #1b1b1b;
  position: relative;
}

.color-swatch.none-swatch::after {
  content: "";
  position: absolute;
  left: 6px;
  right: 6px;
  top: 50%;
  height: 2px;
  background: #777;
  transform: translateY(-50%) rotate(-45deg);
}

#start-game-btn {
  display: block;
  width: 100%;
  padding: 14px;
  font-size: 1.1rem;
  border-radius: 10px;
  border: none;
  background: #3a7bfd;
  color: #fff;
  cursor: pointer;
}

#start-game-btn:disabled {
  background: #333;
  color: #777;
  cursor: not-allowed;
}

/* --- Game view --- */

#game-view {
  display: flex;
  flex-direction: column;
}

.team-zone {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

#home-zone {
  justify-content: flex-end;
  padding-top: env(safe-area-inset-top);
}

#away-zone {
  justify-content: flex-start;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Goal-tap acknowledgement (see flashZone in app.js). */
.team-zone::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

.team-zone.flash::after {
  animation: zone-flash 180ms ease-out;
}

.period-tally.flash {
  animation: tally-bump 180ms ease-out;
}

@keyframes zone-flash {
  from { opacity: 0.35; }
  to { opacity: 0; }
}

@keyframes tally-bump {
  from { transform: scale(1.12); }
  to { transform: scale(1); }
}

.zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

#home-content {
  padding-bottom: 8px;
}

#away-content {
  padding-top: 8px;
}

.zone-content.two-color-badge {
  background: rgba(0, 0, 0, 0.55);
  border-radius: 20px;
  padding: 14px 28px;
  width: auto;
  max-width: calc(100% - 16px);
  margin: 0 auto;
  color: #fff;
}

#home-content.two-color-badge {
  margin-bottom: 8px;
}

#away-content.two-color-badge {
  margin-top: 8px;
}

.team-label {
  max-width: 100%;
  overflow-wrap: anywhere; /* long names without spaces must not overflow */
  text-align: center;
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.period-tally {
  font-size: min(28vw, 220px);
  font-size: min(28vw, 20dvh, 220px);
  line-height: 1;
  font-weight: 700;
}

.closed-periods {
  font-size: 0.95rem;
  opacity: 0.85;
  min-height: 1.2em;
  margin: 4px 0;
}

#control-strip {
  flex: 0 0 auto;
  background: #0b0b0b;
  border-top: 1px solid #222;
  border-bottom: 1px solid #222;
  padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 5;
}

.strip-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 16px;
  font-size: 0.95rem;
}

.strip-buttons {
  flex-wrap: nowrap;
  gap: 6px;
}

.wake-btn {
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid #806a1a;
  background: #3a2f0b;
  color: #ffd54f;
  font-size: 0.8rem;
  cursor: pointer;
}

.strip-btn {
  position: relative;
  overflow: hidden;
  padding: 10px 8px;
  border-radius: 8px;
  border: 1px solid #333;
  background: #1b1b1b;
  color: #eee;
  font-size: 0.85rem;
  cursor: pointer;
  /* Buttons keep their label width; the period-end button takes the rest and
     may wrap, so no label is ever cut off on narrow phones. */
  flex: 1 0 auto;
  white-space: nowrap;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

.strip-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.strip-btn.primary {
  background: #2a2a2a;
  border-color: #555;
  flex: 2 1 auto;
  min-width: 0;
  white-space: normal;
  line-height: 1.15;
}

@media (max-width: 400px) {
  .strip-btn {
    font-size: 0.8rem;
    padding: 10px 6px;
  }
}

#fullscreen-btn {
  flex: 0 0 44px;
  font-size: 1.1rem;
}

/* Phones in landscape: little height, so the strip becomes one row and zone
   content is compacted so both teams stay fully visible. */
@media (max-height: 500px) {
  #control-strip {
    flex-direction: row;
    align-items: center;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  #control-strip .strip-row:first-child {
    flex: 0 1 auto;
    flex-direction: column;
    gap: 2px;
    font-size: 0.85rem;
  }

  #control-strip .strip-buttons {
    flex: 1 1 auto;
  }

  .strip-btn {
    padding: 8px 8px;
  }

  .team-label {
    font-size: 1rem;
  }

  .closed-periods {
    font-size: 0.8rem;
    margin: 2px 0;
  }

  .period-tally {
    font-size: min(28vw, 22dvh, 220px);
  }

  .zone-content.two-color-badge {
    padding: 4px 24px;
  }

  #home-content.two-color-badge {
    margin-bottom: 4px;
  }

  #away-content.two-color-badge {
    margin-top: 4px;
  }
}

.advance-progress {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: rgba(255, 255, 255, 0.25);
  transition: none;
}

/* --- Modals --- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.modal-box {
  background: #1b1b1b;
  border-radius: 14px;
  padding: 24px;
  max-width: 90vw;
  width: 360px;
  text-align: center;
}

.modal-box h2 {
  margin-top: 0;
}

#result-breakdown {
  text-align: left;
  margin: 16px 0;
  font-size: 1rem;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.modal-actions button {
  flex: 1;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #444;
  background: #262626;
  color: #eee;
  font-size: 1rem;
  cursor: pointer;
}

.modal-actions button.primary {
  background: #3a7bfd;
  border-color: #3a7bfd;
}
