/* ============================================================
   DIGITAL FONT (DSEG7Classic — place woff2 in fonts/ to enable)
   ============================================================ */
@font-face {
  font-family: 'Digital';
  src: local('DSEG7Classic-Regular'),
       url('fonts/DSEG7Classic-Regular.woff2') format('woff2');
  font-display: swap;
}

/* ============================================================
   BASE RESET
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #fff;
  /* Prevent text selection and callout on long press */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  /* Prevent double-tap zoom */
  touch-action: manipulation;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
}

/* ============================================================
   APP LAYOUT
   ============================================================ */
#app {
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* dynamic viewport for iOS Safari */
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ============================================================
   DISPLAY AREA — top 68%
   ============================================================ */
#display {
  flex: 0 0 68%;
  display: flex;
  align-items: stretch;
}

/* Shared team panel */
.team-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-width: 0;
}

.team-header {
  width: 100%;
  text-align: center;
  padding: 4px 8px;
  font-size: clamp(12px, 3.5vw, 28px);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.home-bg { background: #1a3a6e; color: #fff; }
.away-bg { background: #8b0000; color: #fff; }

/* Score numbers — large, digital-looking */
.score-num {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Digital', 'Courier New', 'Lucida Console', monospace;
  font-size: clamp(60px, 20vw, 180px);
  font-weight: 900;
  color: #FFD700;
  letter-spacing: -0.02em;
  line-height: 1;
  text-shadow: 0 0 12px rgba(255, 215, 0, 0.4);
  padding: 0 4px;
}

/* CENTER PANEL */
#center-panel {
  flex: 0 0 34%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 4px;
}

/* Period — tap to cycle */
.period-num {
  font-family: 'Digital', 'Courier New', monospace;
  font-size: clamp(20px, 6vw, 52px);
  font-weight: 700;
  color: #aaffaa;
  letter-spacing: 0.05em;
  cursor: pointer;
  padding: 4px 12px;
  border-radius: 6px;
  transition: background 0.1s;
}
.period-num:active { background: rgba(255,255,255,0.1); }

/* Game clock */
.clock-num {
  font-family: 'Digital', 'Courier New', monospace;
  font-size: clamp(32px, 11vw, 96px);
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.04em;
  text-shadow: 0 0 10px rgba(255,255,255,0.3);
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   SHOT CLOCK SECTION — middle 14%
   ============================================================ */
#shot-section {
  flex: 0 0 14%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.03);
  border-top: 1px solid #222;
  border-bottom: 1px solid #222;
}

.shot-num {
  font-family: 'Digital', 'Courier New', monospace;
  font-size: clamp(28px, 10vw, 88px);
  font-weight: 900;
  color: #ff4444;
  letter-spacing: 0.04em;
  text-shadow: 0 0 12px rgba(255, 68, 68, 0.5);
  font-variant-numeric: tabular-nums;
}

/* Flash animation when shot clock <= 5 seconds */
.shot-num.warning {
  animation: flash 0.5s ease-in-out infinite;
}
@keyframes flash {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* ============================================================
   CONTROLS — bottom 18%
   ============================================================ */
#controls {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  padding: 2px 4px;
  gap: 3px;
}

.ctrl-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 3px;
  width: 100%;
  flex: 1;
}

.btn-group {
  display: flex;
  gap: 3px;
  align-items: center;
}

.center-btns {
  flex: 1;
  justify-content: center;
}

#ctrl-row2 {
  justify-content: center;
  gap: 8px;
}

#ctrl-row2 .btn {
  min-width: 84px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  min-height: 44px;
  min-width: 44px;
  padding: 4px 8px;
  border: none;
  border-radius: 6px;
  font-size: clamp(11px, 2.5vw, 18px);
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.03em;
  color: #fff;
  /* Prevent tap highlight flash on iOS */
  -webkit-tap-highlight-color: transparent;
  transition: filter 0.08s, transform 0.08s;
  white-space: nowrap;
  touch-action: manipulation;
}

.btn:active {
  filter: brightness(1.35);
  transform: scale(0.94);
}

.btn.tap-active,
.period-num.tap-active,
.score-num.tap-active,
.shot-num.tap-active {
  filter: brightness(1.35);
  transform: scale(0.94);
}

/* Score: HOME */
.btn-home  { background: #1a5cb5; }

/* Score: AWAY */
.btn-away  { background: #c0392b; }

/* -1 buttons */
.btn-minus { background: #555; }

/* START */
.btn-start { background: #27ae60; }

/* STOP */
.btn-stop  { background: #c0392b; }

/* RESET */
.btn-reset { background: #555; }

/* Shot clock 14 */
.btn-shot14 { background: #7d5a00; color: #FFD700; }

/* Shot clock 24 */
.btn-shot24 { background: #4a4a00; color: #FFD700; }

/* Buzzer */
.btn-buzzer { background: #c78600; color: #000; }

/* Settings */
.btn-setting {
  background: #333;
  font-size: clamp(14px, 3vw, 22px);
  padding: 4px 6px;
}

/* Danger (reset all) */
.btn-danger { background: #8b0000; }

/* ============================================================
   MODALS
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.82);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden { display: none; }

.modal-box {
  background: #111;
  border: 1px solid #444;
  border-radius: 12px;
  padding: 20px 28px;
  min-width: 260px;
  max-width: 90vw;
  color: #fff;
}

.modal-box h2 {
  text-align: center;
  letter-spacing: 0.1em;
  margin-bottom: 16px;
  color: #FFD700;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
}

.setting-row label {
  font-size: 14px;
  color: #ccc;
  white-space: nowrap;
}

.setting-row input[type="text"],
.setting-row select {
  background: #222;
  border: 1px solid #555;
  border-radius: 6px;
  color: #fff;
  padding: 6px 10px;
  font-size: 14px;
  width: 130px;
  -webkit-appearance: none;
  touch-action: manipulation;
}

.setting-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  cursor: pointer;
}

.setting-row .btn {
  width: 100%;
  min-height: 44px;
}

.confirm-btns {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.confirm-btns .btn {
  flex: 1;
  min-height: 48px;
}

#confirm-msg {
  text-align: center;
  font-size: 16px;
  color: #ddd;
}

/* ============================================================
   PORTRAIT LAYOUT FOR IPHONE
   ============================================================ */
@media (orientation: portrait) {
  html,
  body {
    overflow: hidden;
  }

  #app {
    min-height: 100svh;
    height: 100svh;
    padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right))
             max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }

  #display {
    flex: 0 0 56%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: minmax(150px, 1fr) minmax(112px, 0.65fr);
    gap: 6px;
  }

  #home-panel,
  #away-panel {
    min-height: 0;
    background: #030303;
  }

  #center-panel {
    grid-column: 1 / -1;
    grid-row: 2;
    flex: none;
    gap: 2px;
    padding: 0;
    border-top: 1px solid #151515;
  }

  .team-header {
    padding: 7px 6px;
    font-size: clamp(16px, 5vw, 24px);
  }

  .score-num {
    font-size: clamp(92px, 32vw, 164px);
    padding-bottom: 4px;
  }

  .period-num {
    font-size: clamp(20px, 8vw, 34px);
    padding: 0 10px;
  }

  .clock-num {
    font-size: clamp(56px, 19vw, 88px);
    line-height: 1;
  }

  #shot-section {
    flex: 0 0 18%;
  }

  .shot-num {
    font-size: clamp(76px, 27vw, 132px);
    line-height: 1;
  }

  #controls {
    flex: 1;
    min-height: 0;
    justify-content: center;
    gap: 8px;
    padding: 6px 0 0;
  }

  .ctrl-row {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: 1fr;
    gap: 7px;
  }

  #ctrl-row1 {
    grid-template-columns: 1fr;
  }

  .btn-group,
  .center-btns,
  #ctrl-row2 {
    width: 100%;
    justify-content: center;
    gap: 5px;
  }

  #ctrl-row1 .btn-group:first-child {
    order: 2;
  }

  #ctrl-row1 .center-btns {
    order: 1;
  }

  #ctrl-row1 .btn-group:last-child {
    order: 3;
  }

  #ctrl-row2 {
    display: flex;
    justify-content: center;
  }

  #ctrl-row2 .btn {
    flex: 1;
    max-width: 180px;
  }

  .btn {
    min-height: 42px;
    min-width: 48px;
    padding: 5px 9px;
    font-size: clamp(13px, 4vw, 17px);
  }

  .center-btns .btn {
    min-width: 64px;
  }

  .modal-box {
    width: min(92vw, 380px);
    padding: 18px;
  }
}

@media (orientation: portrait) and (max-height: 720px) {
  #display {
    flex-basis: 53%;
    grid-template-rows: minmax(128px, 1fr) minmax(96px, 0.6fr);
  }

  #shot-section {
    flex-basis: 16%;
  }

  .score-num {
    font-size: clamp(76px, 29vw, 132px);
  }

  .clock-num {
    font-size: clamp(46px, 17vw, 72px);
  }

  .shot-num {
    font-size: clamp(62px, 23vw, 106px);
  }

  .btn {
    min-height: 36px;
    font-size: 13px;
  }
}
