:root {
  color-scheme: light;
  --navy: #172033;
  --navy-dark: #0e1524;
  --orange: #ff6b35;
  --orange-dark: #d94a17;
  --yellow: #ffc857;
  --cream: #fff7df;
  --canvas: #f4f6fa;
  --panel: #ffffff;
  --line: #dde2ea;
  --muted: #697386;
  --red: #e63946;
  --green: #21a179;
  --shadow: 0 18px 45px rgba(23, 32, 51, 0.12);
  font-family: Inter, ui-rounded, "Avenir Next", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--canvas); color: var(--navy); }
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app-header {
  min-height: 104px;
  padding: 20px clamp(18px, 4vw, 52px);
  background: var(--navy);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand-lockup { display: flex; align-items: center; gap: 14px; }
.brand-icon { width: 64px; height: 64px; }
h1 { margin: 0; color: var(--yellow); font-size: clamp(1.45rem, 4vw, 2rem); line-height: 1.05; }
.app-header p { margin: 6px 0 0; color: #c8d0de; font-size: 0.92rem; }
.install-button { border: 1px solid rgba(255,255,255,.35); border-radius: 999px; background: transparent; color: white; padding: 11px 18px; font-weight: 800; }

.setup-layout { width: min(1160px, calc(100% - 28px)); margin: 24px auto; display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr); gap: 20px; align-items: start; }
.control-column { display: grid; gap: 16px; }
.control-card, .ready-card { background: var(--panel); border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 8px 24px rgba(23,32,51,.06); }
.control-card { padding: 20px; }
.section-heading { display: flex; gap: 13px; align-items: flex-start; margin-bottom: 18px; }
.section-number { flex: 0 0 auto; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; background: var(--orange); color: white; font-weight: 900; }
.section-heading h2 { margin: 1px 0 3px; font-size: 1.12rem; }
.section-heading p { margin: 0; color: var(--muted); font-size: .9rem; }

.ready-card { position: sticky; top: 18px; min-height: 560px; padding: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; background: var(--navy-dark); color: white; }
.ready-status { position: absolute; top: 22px; left: 24px; font-size: .8rem; text-transform: uppercase; letter-spacing: .09em; font-weight: 850; color: #d8deea; }
.ready-status span { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; background: var(--green); box-shadow: 0 0 0 5px rgba(33,161,121,.15); }
.bomb-frame { position: relative; width: min(290px, 80%); aspect-ratio: 1; display: grid; place-items: center; }
.bomb-frame img { position: relative; width: 100%; z-index: 1; filter: drop-shadow(0 18px 22px rgba(0,0,0,.28)); }
.bomb-halo { position: absolute; inset: 9%; border-radius: 50%; background: rgba(255,200,87,.17); box-shadow: 0 0 0 22px rgba(255,107,53,.08); }
.ready-time { margin-top: 4px; font: 900 clamp(3rem, 8vw, 4.5rem)/1 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--yellow); letter-spacing: -.07em; }
.ready-mode { margin: 10px 0 25px; color: #aeb8c9; font-size: .75rem; font-weight: 850; letter-spacing: .13em; }
.start-button { width: 100%; min-height: 62px; border: 0; border-radius: 16px; background: var(--orange); color: white; font-size: 1.12rem; font-weight: 900; text-transform: uppercase; letter-spacing: .04em; box-shadow: 0 9px 0 #a9320d; }
.start-button:active { transform: translateY(5px); box-shadow: 0 4px 0 #a9320d; }
.awake-note { color: #aeb8c9; text-align: center; font-size: .8rem; margin: 18px 0 0; }

footer { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; padding: 0 18px 28px; color: var(--muted); font-size: .8rem; }

fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #eef1f6;
}
.segmented-control label { position: relative; cursor: pointer; }
.segmented-control input { position: absolute; opacity: 0; pointer-events: none; }
.segmented-control span {
  display: grid;
  min-height: 46px;
  place-items: center;
  border-radius: 10px;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 850;
  transition: background .18s ease, color .18s ease, box-shadow .18s ease;
}
.segmented-control input:checked + span {
  background: white;
  color: var(--navy);
  box-shadow: 0 3px 10px rgba(23, 32, 51, .1);
}
.segmented-control input:focus-visible + span { outline: 3px solid rgba(255, 107, 53, .34); outline-offset: 2px; }

.time-fields { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 12px; align-items: end; }
.time-field, .select-field, .range-field { display: grid; gap: 7px; min-width: 0; }
.time-field > span, .select-field > span, .range-field > span {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .025em;
}
.time-field input, .select-field select {
  width: 100%;
  min-height: 52px;
  border: 1px solid #cbd2dd;
  border-radius: 12px;
  background: white;
  color: var(--navy);
  font-weight: 800;
  padding: 0 14px;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
}
.time-field input { font: 850 1.25rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.time-field input:focus, .select-field select:focus, input[type="range"]:focus-visible {
  border-color: var(--orange);
  box-shadow: 0 0 0 4px rgba(255, 107, 53, .14);
}
.time-separator, .range-word { align-self: end; display: grid; place-items: center; height: 52px; color: var(--muted); font-weight: 900; }
.time-separator { font-size: 1.35rem; }
.range-word { font-size: .82rem; text-transform: uppercase; }

.preset-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 13px; }
.preset-row button, .preview-button, .import-button, .remove-button {
  min-height: 42px;
  border: 1px solid #cbd2dd;
  border-radius: 11px;
  background: white;
  color: var(--navy);
  padding: 0 14px;
  font-size: .82rem;
  font-weight: 850;
  transition: transform .12s ease, background .16s ease, border-color .16s ease;
}
.preset-row button:hover, .preview-button:hover { border-color: var(--orange); background: #fff8f4; }
.preset-row button:active, .preview-button:active, .import-button:active, .remove-button:active { transform: translateY(1px); }

.switch-stack { display: grid; border-top: 1px solid var(--line); }
.switch-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  min-height: 56px;
  border-bottom: 1px solid var(--line);
  color: var(--navy);
  font-size: .91rem;
  font-weight: 750;
  cursor: pointer;
}
.switch-row input { position: absolute; right: 0; opacity: 0; pointer-events: none; }
.switch {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: #c7ced9;
  transition: background .18s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 5px rgba(23, 32, 51, .28);
  transition: transform .18s ease;
}
.switch-row input:checked + .switch { background: var(--orange); }
.switch-row input:checked + .switch::after { transform: translateX(20px); }
.switch-row input:focus-visible + .switch { outline: 3px solid rgba(255, 107, 53, .3); outline-offset: 3px; }
.vibration-row { margin-top: 15px; padding-top: 4px; }

.option-grid, .sound-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: end; margin-top: 16px; }
.preview-button { min-height: 52px; white-space: nowrap; }
.range-field { margin-top: 16px; }
.range-field > span { display: flex; justify-content: space-between; gap: 14px; }
.range-field strong { color: var(--navy); }
input[type="range"] {
  width: 100%;
  height: 8px;
  margin: 7px 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--orange), var(--yellow));
  accent-color: var(--orange);
}
.disabled-control { opacity: .45; }

.import-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 13px; }
.import-button { border-color: var(--navy); background: var(--navy); color: white; }
.import-button:hover { background: #26344e; }
.remove-button { border-color: #efb2b7; color: #b4232e; background: #fff7f7; }
.remove-button:hover { border-color: var(--red); }
.import-status { margin: 10px 0 0; color: var(--muted); font-size: .78rem; }

button:disabled, input:disabled, select:disabled { cursor: not-allowed; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid rgba(255, 107, 53, .34); outline-offset: 3px; }
.install-button:hover { background: rgba(255, 255, 255, .09); }
.start-button:hover { background: #ff7a48; }

body.game-active { overflow: hidden; background: var(--navy-dark); }
.game-view {
  --round-progress: 0;
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 100dvh;
  overflow: hidden;
  padding: max(18px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 50% 44%, rgba(255, 200, 87, .13) 0 19%, transparent 45%),
    linear-gradient(145deg, #111827 0%, #18243a 52%, #0c1322 100%);
  color: white;
}
.game-view::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .13;
  background-image: radial-gradient(rgba(255, 255, 255, .8) .7px, transparent .7px);
  background-size: 22px 22px;
  mask-image: linear-gradient(to bottom, transparent, black 25%, black 75%, transparent);
}
.game-topbar { position: relative; z-index: 2; display: flex; align-items: center; gap: 10px; min-height: 42px; color: #d6dce8; font-size: .82rem; font-weight: 850; letter-spacing: .06em; text-transform: uppercase; }
.live-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--orange); box-shadow: 0 0 0 6px rgba(255, 107, 53, .13); animation: livePulse 1.25s ease-in-out infinite; }
.wake-status { margin-left: auto; padding: 8px 12px; border: 1px solid rgba(255,255,255,.16); border-radius: 999px; color: #b9f0dc; font-size: .7rem; }
.wake-status.unavailable { color: #f6cc89; }

.game-stage { position: relative; z-index: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.game-graphic-wrap { position: relative; width: min(58vh, 68vw, 560px); aspect-ratio: 1; display: grid; place-items: center; }
.game-graphic-wrap img { position: relative; z-index: 2; width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 26px 30px rgba(0,0,0,.42)); animation: bombFloat 2.3s ease-in-out infinite; }
.game-halo { position: absolute; z-index: 1; inset: 9%; border-radius: 50%; background: rgba(255, 200, 87, .16); box-shadow: 0 0 0 30px rgba(255, 107, 53, .09), 0 0 80px rgba(255, 107, 53, .16); transform: scale(1.02); }
.game-time { margin-top: clamp(-20px, -2vh, -8px); color: var(--yellow); font: 950 clamp(2.8rem, 10vw, 7.2rem)/.95 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: -.065em; text-align: center; text-shadow: 0 8px 30px rgba(0,0,0,.32); }
.game-message { margin-top: 12px; color: #eef2f8; font-size: clamp(.82rem, 2vw, 1.12rem); font-weight: 950; letter-spacing: .25em; text-align: center; }
.game-actions { position: relative; z-index: 2; display: flex; justify-content: center; gap: 12px; padding-top: 14px; }
.game-button { min-width: 138px; min-height: 52px; padding: 0 24px; border-radius: 14px; color: white; font-weight: 900; }
.game-button.secondary { border: 1px solid rgba(255,255,255,.3); background: rgba(255,255,255,.08); backdrop-filter: blur(8px); }
.game-button.secondary:hover { background: rgba(255,255,255,.14); }
.game-button.primary { border: 0; background: var(--orange); box-shadow: 0 8px 25px rgba(255,107,53,.28); }
.game-button.primary:hover { background: #ff7a48; }
.game-view.paused .game-graphic-wrap { opacity: .55; filter: grayscale(.35); }
.game-view.paused .game-graphic-wrap img, .game-view.paused .live-dot { animation-play-state: paused; }

.game-view.exploded {
  background:
    radial-gradient(circle at 50% 43%, rgba(255, 200, 87, .2), transparent 40%),
    linear-gradient(145deg, #230d0b, #44150e 55%, #190a0a);
}
.game-view.exploded .game-stage { justify-content: center; }
.game-view.exploded .game-graphic-wrap { width: min(64vh, 78vw, 650px); }
.game-view.exploded .game-graphic-wrap img { animation: explosionIn .58s cubic-bezier(.17,.89,.32,1.35) both; filter: drop-shadow(0 20px 34px rgba(255, 76, 16, .4)); }
.game-view.exploded .game-halo { inset: 2%; background: rgba(255, 107, 53, .17); box-shadow: 0 0 100px rgba(255, 107, 53, .45); animation: blastHalo .9s ease-out both; }
.game-view.exploded .game-time { margin-top: clamp(-52px, -5vh, -22px); color: white; font-family: inherit; font-size: clamp(2.35rem, 8vw, 6.5rem); letter-spacing: .015em; text-transform: uppercase; text-shadow: 0 5px 0 #9c280b, 0 14px 36px rgba(0,0,0,.48); animation: resultIn .45s .12s cubic-bezier(.17,.89,.32,1.25) both; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); max-width: min(90vw, 520px); padding: 12px 17px; border-radius: 12px; background: var(--navy); color: white; font-size: .86rem; font-weight: 750; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translate(-50%, 18px); transition: opacity .2s ease, transform .2s ease; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.success { background: #126f55; }
.toast.error { background: #a42630; }

@keyframes bombFloat { 0%, 100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-10px) rotate(1deg); } }
@keyframes livePulse { 0%, 100% { transform: scale(.9); opacity: .75; } 50% { transform: scale(1.08); opacity: 1; } }
@keyframes explosionIn { 0% { transform: scale(.25) rotate(-14deg); opacity: 0; } 72% { transform: scale(1.08) rotate(3deg); opacity: 1; } 100% { transform: scale(1) rotate(0); opacity: 1; } }
@keyframes blastHalo { from { transform: scale(.35); opacity: .95; } to { transform: scale(1.35); opacity: .16; } }
@keyframes resultIn { from { transform: scale(.72); opacity: 0; } to { transform: scale(1); opacity: 1; } }

@media (max-width: 820px) {
  .setup-layout { grid-template-columns: 1fr; }
  .ready-card { position: static; min-height: 500px; }
  .game-graphic-wrap { width: min(54vh, 78vw, 500px); }
}

@media (max-width: 540px) {
  .app-header { min-height: 88px; padding: 14px 16px; }
  .brand-icon { width: 52px; height: 52px; }
  .app-header p { display: none; }
  .install-button { padding: 9px 12px; font-size: .82rem; }
  .setup-layout { width: min(100% - 20px, 1160px); margin: 12px auto; }
  .control-card { padding: 16px; border-radius: 18px; }
  .ready-card { min-height: 470px; padding: 18px; border-radius: 18px; }
  .time-fields { gap: 8px; }
  .random-fields { grid-template-columns: 1fr; }
  .random-fields .range-word { height: auto; align-self: center; }
  .option-grid, .sound-row { grid-template-columns: 1fr; }
  .preview-button { min-height: 44px; }
  .game-view { padding-left: 14px; padding-right: 14px; }
  .game-topbar { font-size: .72rem; }
  .wake-status { padding: 7px 9px; font-size: .61rem; }
  .game-graphic-wrap { width: min(52vh, 91vw, 440px); }
  .game-actions { width: 100%; }
  .game-button { flex: 1; min-width: 0; padding: 0 16px; }
  .game-view.exploded .game-graphic-wrap { width: min(58vh, 96vw, 500px); }
}

@media (max-height: 620px) and (orientation: landscape) {
  .game-view { grid-template-rows: auto minmax(0, 1fr); }
  .game-stage { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(280px, .9fr); grid-template-rows: 1fr auto; column-gap: 18px; }
  .game-graphic-wrap { grid-row: 1 / 3; width: min(70vh, 43vw, 430px); }
  .game-time { margin: 0; align-self: end; }
  .game-message { align-self: start; }
  .game-actions { position: absolute; right: max(20px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); }
  .game-view.exploded .game-graphic-wrap { width: min(78vh, 48vw, 480px); }
  .game-view.exploded .game-time { margin: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
