:root {
  --bg: #0f1116;
  --panel: #171a22;
  --panel-2: #1e222c;
  --line: #2a2f3b;
  --text: #e7e9ee;
  --muted: #9aa3b2;
  --accent: #4f8cff;
  --ready: #35c46a;
  --ready-dim: #1c6b3c;
  --warn: #ffb020;
  --danger: #ff5f56;
  --radius: 14px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --panel: #ffffff;
    --panel-2: #f0f2f6;
    --line: #dfe3ea;
    --text: #14171d;
    --muted: #5f6875;
    --ready-dim: #b9edcb;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", "Noto Sans TC",
    "Microsoft JhengHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

.loading { color: var(--muted); text-align: center; padding: 40px 0; }

h1 { font-size: 1.35rem; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1rem; margin: 0 0 12px; color: var(--muted); font-weight: 600; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

label { display: block; font-size: 0.85rem; color: var(--muted); margin: 0 0 6px; }

input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 11px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
}
input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field { margin-bottom: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }

button {
  font: inherit;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 11px 16px;
  cursor: pointer;
  transition: filter 0.12s ease, transform 0.06s ease;
}
button:hover:not(:disabled) { filter: brightness(1.15); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary { background: var(--accent); border-color: transparent; color: #fff; }
button.ghost { background: transparent; }
button.wide { width: 100%; }

/* ---------- 對局標題 ---------- */
.match-head { display: flex; gap: 14px; align-items: flex-start; }
.match-head .grow { flex: 1; min-width: 0; }
.match-title { font-size: 1.3rem; font-weight: 700; margin: 0 0 2px; word-break: break-word; }
.match-sub { color: var(--muted); font-size: 0.85rem; }

.shot {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  margin-top: 12px;
}

/* ---------- 玩家格 ---------- */
.slots { display: grid; gap: 10px; min-width: 0; }

.slot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.slot.is-ready { border-color: var(--ready); background: color-mix(in srgb, var(--ready) 12%, var(--panel-2)); }
.slot.is-me { box-shadow: inset 3px 0 0 var(--accent); }

.dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--line); flex: none;
}
.slot.is-ready .dot { background: var(--ready); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ready) 25%, transparent); }

.slot-name {
  flex: 1 1 0; min-width: 0; width: 0;
  background: transparent; border: 0; padding: 0;
  color: var(--text); font: inherit; font-weight: 600;
  text-overflow: ellipsis;
}
.slot-name:focus { outline: none; border-bottom: 1px dashed var(--muted); }

.countdown {
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  color: var(--muted);
  flex: none;
  min-width: 3.2em;
  text-align: right;
}
.countdown.urgent { color: var(--warn); font-weight: 700; }

.slot button.mini { padding: 7px 12px; font-size: 0.85rem; flex: none; }
.slot button.on { background: var(--ready); border-color: transparent; color: #06301a; }

/* ---------- 全員 ready 橫幅 ---------- */
.banner {
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
  font-weight: 700;
  text-align: center;
  background: var(--ready);
  color: #06301a;
  animation: pop 0.3s ease;
}
@keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.hint { color: var(--muted); font-size: 0.85rem; margin-top: 10px; }
.err { color: var(--danger); font-size: 0.88rem; margin-top: 10px; min-height: 1.2em; }

.share {
  display: flex; gap: 8px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; margin-top: 10px;
}
.share input { border: 0; background: transparent; padding: 0; font-size: 0.85rem; }

.status-line {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.82rem; color: var(--muted); margin-bottom: 12px;
}
.pill {
  width: 8px; height: 8px; border-radius: 50%; background: var(--muted);
}
.pill.live { background: var(--ready); }
.pill.down { background: var(--danger); }

.file-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.file-name { font-size: 0.82rem; color: var(--muted); }

/* ---------- 全螢幕 Ready 覆蓋層(不靠系統通知的提示) ---------- */
#ready-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(6, 48, 26, 0.72);
  backdrop-filter: blur(2px);
}
#ready-overlay.show {
  display: flex;
  animation: ov-flash 0.9s ease-in-out infinite alternate;
}
@keyframes ov-flash {
  from { background: rgba(6, 48, 26, 0.72); }
  to { background: rgba(53, 196, 106, 0.82); }
}
.ov-inner {
  text-align: center;
  color: #fff;
  max-width: 420px;
}
.ov-big {
  font-size: clamp(2.2rem, 12vw, 4rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}
.ov-sub {
  font-size: 1.1rem;
  margin-top: 8px;
  opacity: 0.95;
  word-break: break-word;
}
.ov-dismiss {
  margin-top: 24px;
  background: #fff;
  color: #06301a;
  border: 0;
  font-weight: 700;
  padding: 12px 28px;
  border-radius: 999px;
  font-size: 1rem;
}
@media (prefers-reduced-motion: reduce) {
  #ready-overlay.show { animation: none; background: rgba(53, 196, 106, 0.85); }
}

/* ---------- iOS 加主畫面引導條 ---------- */
#ios-hint {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
  background: var(--accent);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1.4;
}
#ios-hint b { font-weight: 700; }
#ios-hint button {
  margin-left: auto;
  flex: none;
  background: rgba(255, 255, 255, 0.2);
  border: 0;
  color: #fff;
  width: 28px; height: 28px;
  border-radius: 50%;
  font-size: 0.9rem;
  line-height: 1;
}
