:root {
  --c-primary: #0b5394;
  --c-accent: #d62839;
  --c-yellow: #ffed4e;
}

/* DSEG7-Classic (7-segment LCD font) — 古めかしい電卓風 — self-hosted */
@font-face {
  font-family: 'DSEG7-Classic';
  src: url('/assets/fonts/DSEG7Classic-Bold.woff2') format('woff2'),
       url('/assets/fonts/DSEG7Classic-Bold.woff') format('woff');
  font-weight: bold;
  font-display: swap;
}
html, body {
  font-family: 'Noto Sans JP', sans-serif;
  /* iOS: no pull-to-refresh flicker on autoplay animations */
  overscroll-behavior: none;
}
.font-display { font-family: 'M PLUS Rounded 1c', 'Noto Sans JP', sans-serif; }

/* iPad/phone: タップハイライト抑止、ダブルタップズーム抑止 */
body { -webkit-tap-highlight-color: transparent; }
button, .evt-btn, .bench-player, .court-player, .modal button, .modal input, .modal select {
  touch-action: manipulation;
}

/* Safe area (iPhone notch / iPad home indicator) */
main { padding-bottom: env(safe-area-inset-bottom, 0); }

/* Court — IHF公式規格 40m x 20m を aspect 2:1 で描画
   デスクトップ: 両サイドにscoreboard空間 (140px*2) 確保
   iPad portrait/phone: 全幅利用、scoreboardはコート内隅に吸収 */
.court {
  position: relative;
  aspect-ratio: 2/1;
  width: calc(100% - 280px);
  max-width: 820px;
  margin: 0 auto;
  background: linear-gradient(180deg, #2d7c4a 0%, #24663d 100%);
  border: 3px solid #fff;
  border-radius: 6px;
  user-select: none;
  touch-action: none;
  overflow: visible;
}
/* iPad landscape: 1024px近辺でもサイド余白あり */
@media (max-width: 1024px) {
  .court { width: 100%; max-width: 100%; }
}
.court-svg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
  overflow: visible;
}
/* Goal — JPN ハンドボール公式規格 (紅白ポスト + ネット)
   参考: ZETT ZKN301 (紅白縦ストライプポスト + 白枠 + 白黒ネット) */
.goal-struct {
  position: absolute;
  top: 42.5%; height: 15%;  /* 3m / 20m = 15% of court height */
  width: 24px;
  z-index: 3;
  /* Netの背景 (暗色ベース+メッシュ) */
  background:
    linear-gradient(45deg, transparent 45%, rgba(255,255,255,.28) 49%, rgba(255,255,255,.28) 51%, transparent 55%),
    linear-gradient(-45deg, transparent 45%, rgba(255,255,255,.28) 49%, rgba(255,255,255,.28) 51%, transparent 55%),
    linear-gradient(180deg, #1a1a1a, #2e2e2e);
  background-size: 6px 6px, 6px 6px, 100% 100%;
  border: 2px solid #ffffff;
  box-shadow:
    0 0 0 1px #111,
    0 4px 8px rgba(0,0,0,.45),
    inset 0 0 6px rgba(0,0,0,.6);
  border-radius: 2px;
}
.goal-struct.left  { left:  -24px; }
.goal-struct.right { right: -24px; }

/* 紅白縦ストライプポスト (field-facingエッジ) */
.goal-post-v {
  position: absolute;
  top: -4px; bottom: -4px;
  width: 7px;
  background: repeating-linear-gradient(
    180deg,
    #d62839 0 9px,
    #ffffff 9px 18px
  );
  border: 1px solid #111;
  border-radius: 1px;
  box-shadow: 0 2px 3px rgba(0,0,0,.4);
  z-index: 1;
}
.goal-struct.left  .goal-post-v { right: -7px; }
.goal-struct.right .goal-post-v { left:  -7px; }

/* 紅白横ストライプバー (上下のクロスバー相当) */
.goal-bar-h {
  position: absolute;
  left: -3px; right: -3px;
  height: 5px;
  background: repeating-linear-gradient(
    90deg,
    #d62839 0 7px,
    #ffffff 7px 14px
  );
  border: 1px solid #111;
  border-radius: 1px;
  box-shadow: 0 1px 2px rgba(0,0,0,.4);
  z-index: 1;
}
.goal-bar-h.top    { top: -6px; }
.goal-bar-h.bottom { bottom: -6px; }

/* shot marker */
.shot-dot {
  position: absolute; width: 14px; height: 14px; border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 2px solid #fff; box-shadow: 0 0 0 1px #111;
}

/* The live ball (2x shot marker, white/yellow pulsing, straight-line movement) */
.ball {
  position: absolute;
  width: 28px; height: 28px;
  left: 50%; top: 50%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffffff 0%, #fff5a1 40%, #ffed4e 80%);
  border: 2px solid #ff8a1e;
  box-shadow: 0 0 18px rgba(255,237,78,.95), 0 0 6px rgba(255,255,255,.9) inset;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 25;
  transition: left .6s linear, top .6s linear;
  animation: ball-pulse 0.55s infinite alternate;
}
@keyframes ball-pulse {
  0%   { box-shadow: 0 0 12px rgba(255,237,78,.7), 0 0 3px rgba(255,255,255,.8) inset;
         background: radial-gradient(circle at 35% 35%, #ffffff 0%, #fff5a1 40%, #ffed4e 80%); }
  100% { box-shadow: 0 0 28px rgba(255,255,255,1), 0 0 8px rgba(255,237,78,.9) inset;
         background: radial-gradient(circle at 35% 35%, #ffed4e 0%, #ffffff 50%, #ffed4e 90%); }
}
.ball.fast { transition: left .35s linear, top .35s linear; }
.ball.slow { transition: left 1s ease-out, top 1s ease-out; }
.ball.shoot { transition: left .5s linear, top .5s linear; }

/* Goal flash on score */
.goal-flash {
  position: absolute; top: 10%; bottom: 10%; width: 10%;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(255,237,78,.9), transparent 70%);
  animation: goal-flash-anim 1.2s ease-out forwards;
}
.goal-flash.left  { left: -1%; }
.goal-flash.right { right: -1%; }
@keyframes goal-flash-anim {
  0%   { opacity: 0; transform: scale(.4); }
  30%  { opacity: 1; transform: scale(1.2); }
  100% { opacity: 0; transform: scale(1.4); }
}

/* Electronic scoreboard — 古めかしい電卓LCD (DSEG7) 黄色デジタル */
.scoreboard {
  position: absolute;
  top: 28%;
  width: 64px;
  height: 44%;
  /* 電卓風アンバー暗色地 */
  background:
    linear-gradient(180deg, #1a1508 0%, #0f0b04 60%, #1a1508 100%);
  border: 2px solid #1a1a1a;
  border-radius: 5px;
  box-shadow:
    0 0 0 2px #3a2e18,
    0 0 0 3px #0a0a0a,
    0 4px 8px rgba(0,0,0,.55),
    inset 0 0 8px rgba(0,0,0,.8),
    inset 0 1px 0 rgba(255,230,0,.1);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 5;
  padding: 4px 4px;
}
.scoreboard .sb-label {
  font-family: 'Courier New', monospace;
  font-size: 8px;
  color: #ffe600;
  font-weight: 900;
  letter-spacing: 2px;
  opacity: 0.55;
  text-shadow: 0 0 3px rgba(255,230,0,.4);
  margin-bottom: 3px;
}
/* LCD 数字枠 (ghost 88 + real digits 重ね) */
.sb-display {
  position: relative;
  line-height: 1;
  font-family: 'DSEG7-Classic', 'Courier New', monospace;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 2px;
}
.sb-ghost {
  /* 非点灯セグメントの薄い "88" */
  position: absolute; inset: 0;
  color: rgba(255,230,0,.07);
  font-family: inherit; font-weight: inherit; font-size: inherit; letter-spacing: inherit;
  pointer-events: none;
}
.scoreboard .sb-num {
  position: relative;
  color: #ffe600;  /* 黄色 LCD */
  text-shadow:
    0 0 2px rgba(255,230,0,.9),
    0 0 6px rgba(255,200,0,.55),
    0 0 12px rgba(255,150,0,.25);
  font-family: inherit; font-weight: inherit; font-size: inherit; letter-spacing: inherit;
  /* slow-change transition (1秒) */
  transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out, filter 0.5s ease-in-out;
  transform-origin: center center;
  font-variant-numeric: tabular-nums;
  display: inline-block;
}
/* HOME/AWAY 共通で黄色 (従来の赤/青は廃止) */
.scoreboard.home .sb-num,
.scoreboard.away .sb-num { color: #ffe600; }

/* ゴール枠 (-24px, 幅24px, 右端=0) から 約30px の間隔を空けて電光掲示板配置 */
.scoreboard.left  { left:  -132px; }  /* 右端 = -68, ゴール左端 -24 との間隔 44px */
.scoreboard.right { right: -132px; }

/* 数字切替時: scaleY を 0 → 1 に戻す (古電卓のリフレッシュ感) */
.sb-num.changing {
  transform: scaleY(0.05);
  filter: blur(1px) brightness(1.4);
  opacity: 0.4;
}
/* 得点時のflash: 一瞬発光が強くなる */
.scoreboard.flash {
  animation: sb-flash 0.9s ease-out 2;
}
@keyframes sb-flash {
  0%, 100% {
    box-shadow:
      0 0 0 2px #3a2e18, 0 0 0 3px #0a0a0a,
      0 4px 8px rgba(0,0,0,.55),
      inset 0 0 8px rgba(0,0,0,.8);
  }
  50% {
    box-shadow:
      0 0 0 2px #ffe600, 0 0 0 3px #1a1a1a,
      0 0 24px rgba(255,230,0,.9),
      inset 0 0 8px rgba(0,0,0,.4);
  }
}

/* Player on the court with ball indicator */
.court-player.has-ball {
  box-shadow: 0 0 0 4px rgba(255,237,78,.6), 0 0 16px rgba(255,237,78,.9);
}

/* iPad portrait・phone: scoreboardsをコート内TOP左右コーナーに配置 (プレー位置とぶつかりにくい) */
@media (max-width: 1024px) {
  .scoreboard {
    top: 2%;
    height: 22%;
    width: 56px;
    z-index: 6;
  }
  .scoreboard.left  { left: 2px; right: auto; }
  .scoreboard.right { right: 2px; left: auto; }
  .scoreboard .sb-display { font-size: 22px; }
  .scoreboard .sb-label { font-size: 6px; letter-spacing: 1px; }
}
@media (max-width: 480px) {
  .scoreboard { width: 46px; height: 20%; }
  .scoreboard .sb-display { font-size: 17px; }
  .scoreboard .sb-label { font-size: 5px; }
}

/* ==========================================
   iPad/phone: UI全般のタッチ最適化
   ========================================== */
@media (max-width: 1024px) {
  /* コート選手: タップしやすく */
  .court-player { width: 44px; height: 44px; font-size: 15px; border-width: 2.5px; }
  /* ベンチ選手カード: 指で押しやすいサイズ */
  .bench-player { min-width: 72px; padding: 10px 4px; font-size: 11.5px; }
  .bench-player .num { width: 36px; height: 36px; font-size: 16px; }
  /* イベントボタン: 高さと文字 */
  .evt-btn { min-height: 56px; font-size: 13.5px; padding: 10px 6px; }
  .evt-btn .sub { font-size: 9px; }
  /* モーダルは90vh以内に */
  .modal {
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* ボール: モバイルでもしっかり視認 */
  .ball { width: 26px; height: 26px; }
}

@media (max-width: 480px) {
  .court-player { width: 38px; height: 38px; font-size: 13px; }
  .bench-player { min-width: 64px; padding: 8px 3px; }
  .bench-player .num { width: 32px; height: 32px; font-size: 14px; }
  .evt-btn { min-height: 50px; font-size: 12px; padding: 8px 4px; }
  .evt-btn .sub { font-size: 8px; }
}
.shot-dot.goal { background: #ffed4e; }
.shot-dot.save { background: #6b6b6b; opacity: .8; }
.shot-dot.miss { background: transparent; border-color: #ff5c38; border-style: dashed; }
.shot-dot.block { background: #1a1a1a; }
.shot-dot.post { background: #ff8a1e; }

/* player chip on court */
.court-player {
  position: absolute; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  transform: translate(-50%, -50%);
  font-weight: 900; color: #fff; font-size: 14px;
  border: 2px solid #fff; cursor: grab;
  touch-action: none;
  user-select: none;
  transition: transform .1s;
}
.court-player:active { cursor: grabbing; transform: translate(-50%, -50%) scale(1.1); }
.court-player.selected { outline: 3px solid #ffed4e; outline-offset: 2px; }
.court-player.home { background: var(--c-accent); }
.court-player.away { background: var(--c-primary); }

/* bench bar */
.bench {
  display: flex; gap: 8px; overflow-x: auto; padding: 6px; background: #f4f0e4; border-radius: 6px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.bench-player {
  flex-shrink: 0; min-width: 62px; padding: 8px 4px; text-align: center; border-radius: 4px;
  background: #fff; border: 2px solid transparent; cursor: pointer; font-size: 11px;
  scroll-snap-align: start;
}
.bench-player:hover { border-color: var(--c-primary); }
.bench-player .num {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  color: #fff; font-weight: 900; font-size: 14px; margin-bottom: 2px;
}
.bench-player.home .num { background: var(--c-accent); }
.bench-player.away .num { background: var(--c-primary); }

/* event buttons */
.evt-btn {
  padding: 12px 10px; border-radius: 8px; font-weight: 800;
  border: 2px solid #1a1a1a; background: #fff; cursor: pointer;
  min-height: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  transition: transform .05s;
}
.evt-btn:active { transform: translateY(1px); }
.evt-btn.primary { background: #ffed4e; }
.evt-btn.danger { background: #ff5c38; color: #fff; }
.evt-btn.safe { background: #a8dfb5; }
.evt-btn .sub { font-size: 10px; font-weight: 500; color: #555; margin-top: 2px; }

/* tables */
.tbl { width: 100%; border-collapse: collapse; background: #fff; }
.tbl th { background: #1a1a1a; color: #fff; font-weight: 700; padding: 8px 6px; text-align: left; font-size: 12px; }
.tbl td { border-top: 1px solid #eee; padding: 8px 6px; font-size: 13px; }
.tbl tr:hover td { background: #fffbeb; }

/* offline indicator */
.offline-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  background: #ff5c38; color: #fff; text-align: center; padding: 6px;
  font-size: 12px; font-weight: 700;
}

/* toast */
#toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: #1a1a1a; color: #ffed4e; padding: 10px 18px;
  border-radius: 999px; font-weight: 700; font-size: 13px; z-index: 100;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
#toast.show { opacity: 1; }

/* confirm modal */
.modal-backdrop {
  position: fixed; inset: 0; background: #0009; z-index: 90;
  display: grid; place-items: center;
  padding: 16px;
  /* iOS: scroll inside modal, not on backdrop */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  width: min(460px, 100%);
  max-height: calc(100dvh - 32px);
  max-height: calc(100vh - 32px); /* fallback */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* heatmap cell */
.heat-cell { position: relative; }
.heat-cell .bar { position: absolute; left: 4px; right: 4px; bottom: 4px; background: #d62839; border-radius: 2px; opacity: .7; }

/* ===== PDF / Print layout ===== */
.pdf-root { background: #f5f5f5; }
.pdf-page {
  background: #fff;
  width: 210mm;
  min-height: 297mm;
  margin: 12px auto;
  padding: 14mm 12mm;
  box-shadow: 0 4px 18px rgba(0,0,0,.12);
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 10.5pt;
  color: #111;
}
.pdf-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 3px solid #111; padding-bottom: 8px; margin-bottom: 10px; }
.pdf-title { font-size: 18pt; font-weight: 900; }
.pdf-sub { font-size: 10pt; color: #333; }
.pdf-logo { display: flex; align-items: center; gap: 8px; }
.pdf-logo-sq { width: 44px; height: 44px; background: #111; color: #ffed4e; display: grid; place-items: center; font-weight: 900; font-size: 22pt; border-radius: 6px; }
.pdf-logo-name { font-weight: 900; font-size: 14pt; }
.pdf-logo-sub { font-size: 9pt; color: #555; }
.pdf-h3 { font-size: 13pt; font-weight: 900; margin: 14px 0 4px; border-bottom: 2px solid #111; padding-bottom: 2px; }
.pdf-h4 { font-size: 11pt; font-weight: 900; margin: 8px 0 4px; }

.pdf-score { width: 100%; border: 2px solid #111; border-collapse: collapse; margin: 8px 0; }
.pdf-score th { background: #111; color: #ffed4e; padding: 6px; font-weight: 900; font-size: 11pt; }
.pdf-score td { text-align: center; padding: 8px; }
.pdf-big-score { font-size: 40pt; font-weight: 900; font-family: 'M PLUS Rounded 1c', sans-serif; }
.pdf-home { background: #fdeeef; color: #a21e2b; }
.pdf-away { background: #e8edf8; color: #143c77; }
.pdf-status { font-weight: 700; font-size: 10pt; color: #444; }

.pdf-tbl { width: 100%; border-collapse: collapse; margin: 4px 0 10px; }
.pdf-tbl th, .pdf-tbl td { border: 1px solid #222; padding: 4px 6px; font-size: 9.5pt; }
.pdf-tbl th { background: #e9e9e9; font-weight: 700; }
.pdf-tbl .pdf-v { text-align: center; font-weight: 700; }
.pdf-tbl .pdf-l { text-align: center; font-size: 10pt; }

.pdf-players { font-size: 9pt; }
.pdf-players th, .pdf-players td { padding: 3px 5px; }
.pdf-legend { font-size: 8pt; color: #555; margin-top: 2px; }

.pdf-two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.pdf-col { }

.pdf-log td { font-size: 9pt; padding: 2px 5px; }
.pdf-log tr:nth-child(even) td { background: #fafafa; }

.pdf-footer { display: flex; justify-content: space-between; border-top: 1px solid #ccc; margin-top: 16px; padding-top: 6px; font-size: 8pt; color: #555; }

@media print {
  @page { size: A4; margin: 0; }
  body, html { background: #fff !important; }
  .no-print, header, nav, #toast, #offline-banner, .modal-backdrop { display: none !important; }
  .pdf-root { background: #fff !important; }
  .pdf-page {
    box-shadow: none !important;
    margin: 0 !important;
    padding: 12mm 10mm !important;
    width: 100% !important;
    min-height: 0 !important;
  }
  .pdf-tbl, .pdf-score { page-break-inside: avoid; }
}

/* hide by default for screen preview */
.hidden { display: none; }
