:root {
  color-scheme: dark;
  --bg: #07060b;
  --panel: rgba(9, 9, 18, 0.72);
  --panel-strong: rgba(12, 10, 20, 0.88);
  --gold: #f1cb7a;
  --amber: #ff9f4d;
  --rose: #f05fa5;
  --ink: #05050a;
  --text: #fff2cf;
  --muted: #d0a968;
}

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 30% 10%, rgba(119, 42, 139, 0.22), transparent 30%),
    radial-gradient(circle at 80% 88%, rgba(217, 99, 40, 0.16), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: ui-serif, Georgia, "Times New Roman", serif;
  touch-action: none;
}

button {
  min-width: 42px;
  height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(241, 203, 122, 0.56);
  border-radius: 8px;
  background: rgba(14, 13, 23, 0.82);
  color: var(--gold);
  font: 700 1.18rem/1 system-ui, sans-serif;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.28);
  cursor: pointer;
}

button:active {
  transform: translateY(1px);
}

.game-shell {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 320px;
  min-height: 100%;
  padding:
    max(10px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    env(safe-area-inset-bottom)
    max(12px, env(safe-area-inset-left));
}

.playfield-wrap {
  position: relative;
  grid-row: 2;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100vw;
  height: 100vh;
  cursor: crosshair;
  touch-action: none;
}

.hud {
  position: relative;
  grid-row: 1;
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  min-height: 54px;
  width: 100%;
  margin-bottom: 14px;
  padding: 8px;
  border: 1px solid rgba(241, 203, 122, 0.32);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(8, 7, 13, 0.84), rgba(8, 7, 13, 0.58));
  box-shadow: 0 12px 38px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(10px);
}

.stats {
  display: grid;
  grid-column: 3;
  grid-row: 1;
  justify-items: end;
  gap: 2px;
  min-width: 78px;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#timer {
  color: #fff8dd;
  font-size: 1rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

#statusText {
  max-width: 112px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.actions {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  justify-content: center;
  gap: 8px;
}

#restartButton {
  width: auto;
  min-width: min(58vw, 230px);
  font-size: 0.86rem;
  letter-spacing: 0;
  white-space: nowrap;
}

.loading,
.toast {
  position: fixed;
  z-index: 4;
  left: 50%;
  translate: -50% 0;
  max-width: min(88vw, 420px);
  border: 1px solid rgba(241, 203, 122, 0.36);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(10px);
  text-align: center;
}

.loading {
  top: 48%;
  padding: 14px 18px;
}

.loading.is-hidden {
  display: none;
}

.toast {
  bottom: max(16px, env(safe-area-inset-bottom));
  padding: 12px 14px;
  font: 700 0.9rem/1.35 ui-sans-serif, system-ui, sans-serif;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  transform: translateY(10px);
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 380px) {
  .hud {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .stats {
    grid-column: 1;
    grid-row: 2;
    justify-items: center;
  }

  .actions {
    grid-column: 1;
    grid-row: 1;
  }
}
