:root {
  --ink: #d6e7ee;
  --ink-dim: #89a4b1;
  --ink-faint: #5d7583;
  --gold: #e3bd70;
  --panel: rgba(11, 24, 34, 0.84);
  --hairline: rgba(215, 235, 245, 0.16);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #10283a;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

#tank {
  position: fixed;
  inset: 0;
  display: block;
}

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 120% 90% at 50% 40%, transparent 62%, rgba(0, 0, 0, 0.24) 100%);
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */

.hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(22px + env(safe-area-inset-top, 0px))
           calc(28px + env(safe-area-inset-right, 0px))
           22px
           calc(28px + env(safe-area-inset-left, 0px));
  pointer-events: none;
  z-index: 10;
}
.hud > * { pointer-events: auto; }

.brand {
  font-size: 18px;
  font-weight: 300;
  letter-spacing: 0.38em;
  color: #c3d8e1;
  text-shadow: 0 0 14px rgba(150, 205, 225, 0.18);
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 18px;
}
.coins {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 300;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.coins.small { font-size: 13px; }

.coin-dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ecd39e, #b8904e 70%);
  box-shadow: 0 0 8px rgba(216, 176, 106, 0.35);
  display: inline-block;
  flex: none;
}
.coin-dot.small { width: 8px; height: 8px; }

/* ---------- buttons ---------- */

button {
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background: none;
  border: none;
  color: inherit;
}

.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 98px;
  font-size: 11px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0.22em;
  color: var(--ink-dim);
  padding: 8px 14px;
  border: 1px solid var(--hairline);
  border-radius: 2px;
  background: rgba(13, 33, 45, 0.5);
  text-decoration: none;
  transition: color 0.25s, border-color 0.25s;
}
.ghost-btn:hover { color: var(--ink); border-color: rgba(185, 199, 209, 0.3); }
.ghost-btn.danger:hover { color: #c98a7a; border-color: rgba(201, 138, 122, 0.35); }
.ghost-btn.tiny { font-size: 9px; padding: 5px 9px; letter-spacing: 0.15em; }
.hud-right .hud-btn {
  box-sizing: border-box;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: 126px !important;
  min-width: 126px !important;
  max-width: 126px !important;
  height: 44px !important;
  min-height: 44px !important;
  max-height: 44px !important;
  flex: 0 0 126px !important;
  padding: 0 !important;
  line-height: 1;
  overflow: hidden;
}
.hud-right button.hud-btn,
.hud-right a.hud-btn {
  width: 126px !important;
  min-width: 126px !important;
  max-width: 126px !important;
  height: 44px !important;
  min-height: 44px !important;
  max-height: 44px !important;
}
.shop-head .ghost-btn,
.run-controls .ghost-btn,
.ghost-btn.tiny {
  min-width: 0;
}

.star-link span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  font-size: 13px;
  line-height: 1;
  letter-spacing: 0;
  filter: drop-shadow(0 0 5px rgba(227, 189, 112, 0.35));
}

.primary-btn {
  font-size: 13px;
  font-weight: 300;
  letter-spacing: 0.3em;
  color: var(--ink);
  padding: 13px 44px;
  border: 1px solid rgba(185, 199, 209, 0.25);
  border-radius: 2px;
  background: rgba(17, 40, 54, 0.55);
  transition: all 0.3s;
}
.primary-btn:hover {
  border-color: rgba(216, 176, 106, 0.5);
  color: #e6eef4;
  box-shadow: 0 0 24px rgba(120, 160, 190, 0.12);
}

/* ---------- timer panel ---------- */

.timer-panel {
  position: fixed;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 5;
  pointer-events: none;
}
.timer-panel button, .timer-panel input, .timer-panel .chip { pointer-events: auto; }

.chips {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 30px;
  flex-wrap: wrap;
}

.chip {
  font-size: 11px;
  letter-spacing: 0.18em;
  font-weight: 300;
  color: var(--ink-dim);
  padding: 9px 16px;
  border: 1px solid var(--hairline);
  border-radius: 2px;
  background: rgba(13, 33, 45, 0.5);
  transition: all 0.25s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.chip:hover { color: var(--ink); }
.chip.selected {
  color: #e6eef4;
  border-color: rgba(216, 176, 106, 0.45);
}

.custom-chip input {
  width: 44px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--hairline);
  color: var(--ink);
  font-family: inherit;
  font-size: 12px;
  text-align: center;
  outline: none;
  padding: 2px 0;
  font-variant-numeric: tabular-nums;
}
.custom-chip input::-webkit-outer-spin-button,
.custom-chip input::-webkit-inner-spin-button { -webkit-appearance: none; }
.custom-chip input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.custom-chip span { font-size: 10px; color: var(--ink-faint); letter-spacing: 0.18em; }

.note {
  margin-top: 22px;
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 14px;
}

.time {
  font-size: clamp(64px, 11vw, 118px);
  font-weight: 100;
  letter-spacing: 0.04em;
  color: #d5e2ea;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 40px rgba(120, 160, 190, 0.25);
  line-height: 1;
}
.time.paused { color: var(--ink-dim); text-shadow: none; }

.progress {
  width: min(340px, 60vw);
  height: 1px;
  background: rgba(185, 199, 209, 0.12);
  margin: 30px auto 26px;
  position: relative;
}
#progressFill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, rgba(216, 176, 106, 0.5), var(--gold));
  box-shadow: 0 0 8px rgba(216, 176, 106, 0.4);
  transition: width 0.5s linear;
}

.run-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ---------- empty hint ---------- */

.empty-hint {
  position: fixed;
  left: 50%;
  bottom: 18%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 86vw;
  text-align: center;
  line-height: 1.9;
  font-size: 12px;
  font-weight: 300;
  letter-spacing: 0.2em;
  color: var(--ink-faint);
  z-index: 4;
  pointer-events: none;
  animation: breathe 5s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.9; }
}

/* ---------- shop ---------- */

.shop {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 340px;
  max-width: 92vw;
  background: var(--panel);
  border-left: 1px solid var(--hairline);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  z-index: 20;
  display: flex;
  flex-direction: column;
  transform: translateX(105%);
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  padding-right: env(safe-area-inset-right, 0px);
}
.shop.open { transform: translateX(0); }

.shop-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: calc(22px + env(safe-area-inset-top, 0px)) 22px 16px;
  border-bottom: 1px solid var(--hairline);
}
.shop-title {
  font-size: 12px;
  letter-spacing: 0.3em;
  color: var(--ink-dim);
  flex: 1;
}
.shop-head .ghost-btn { border: none; font-size: 18px; padding: 2px 8px; letter-spacing: 0; }

.shop-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--ink-faint) transparent;
}

.shop-section {
  padding: 14px 20px 7px;
  font-size: 9px;
  letter-spacing: 0.28em;
  color: var(--ink-faint);
  border-bottom: 1px solid rgba(185, 199, 209, 0.04);
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 20px;
  border-bottom: 1px solid rgba(185, 199, 209, 0.05);
}

.shop-thumb {
  width: 90px;
  height: 60px;
  flex: none;
  border: 1px solid rgba(215, 235, 245, 0.12);
  border-radius: 4px;
  background: rgba(18, 43, 58, 0.32);
  box-shadow: inset 0 0 14px rgba(115, 175, 205, 0.08);
}

.shop-info { flex: 1; min-width: 0; }

.shop-name {
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.12em;
  color: var(--ink);
  text-transform: uppercase;
}
.shop-desc {
  font-size: 10.5px;
  font-weight: 300;
  color: var(--ink-dim);
  margin-top: 3px;
  line-height: 1.45;
}
.shop-owned {
  font-size: 10px;
  color: var(--ink-faint);
  letter-spacing: 0.1em;
  margin-top: 3px;
}

.shop-buy {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.shop-price {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.buy-btn {
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--ink-dim);
  padding: 6px 14px;
  border: 1px solid var(--hairline);
  border-radius: 2px;
  transition: all 0.25s;
}
.buy-btn:not(:disabled):hover {
  color: var(--gold);
  border-color: rgba(216, 176, 106, 0.4);
}
.buy-btn:disabled { opacity: 0.3; cursor: default; }

.shop-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--hairline);
  font-size: 10px;
  font-weight: 300;
  color: var(--ink-faint);
  letter-spacing: 0.08em;
}

/* ---------- labels & toast ---------- */

.creature-label {
  position: fixed;
  transform: translate(-50%, -100%);
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: rgba(213, 226, 234, 0.85);
  text-shadow: 0 0 12px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  z-index: 15;
  transition: opacity 0.6s;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 9%;
  transform: translateX(-50%);
  max-width: min(760px, calc(100vw - 32px));
  font-size: 13px;
  font-weight: 300;
  letter-spacing: 0.18em;
  line-height: 1.45;
  text-align: center;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 2px;
  padding: 12px 26px;
  z-index: 30;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.5s;
  white-space: normal;
}
.toast.show { opacity: 1; }
.toast .coin-dot { vertical-align: middle; }

/* ---------- touch & small screens ---------- */

/* On touch devices an input under 16px makes iOS zoom the page on focus. */
@media (pointer: coarse) {
  .custom-chip input {
    font-size: 16px;
    width: 54px;
  }
}

@media (max-width: 640px) {
  .hud {
    padding: calc(12px + env(safe-area-inset-top, 0px))
             calc(14px + env(safe-area-inset-right, 0px))
             12px
             calc(16px + env(safe-area-inset-left, 0px));
  }
  .brand {
    font-size: 13px;
    letter-spacing: 0.3em;
  }
  .hud-right { gap: 8px; }
  .hud-right .hud-btn,
  .hud-right button.hud-btn,
  .hud-right a.hud-btn {
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    flex: 0 0 auto !important;
    height: 38px !important;
    min-height: 38px !important;
    max-height: 38px !important;
    padding: 0 12px !important;
    font-size: 10px;
    letter-spacing: 0.16em;
  }
  .coins { font-size: 14px; gap: 6px; }

  .timer-panel { width: min(94vw, 560px); }
  .chips { gap: 8px; margin-bottom: 24px; }
  .chip { padding: 10px 12px; }
  .progress { width: 70vw; }
  .run-controls .ghost-btn { padding: 12px 18px; }
  .note { letter-spacing: 0.1em; }

  .empty-hint { bottom: 22%; }

  .shop {
    width: 100%;
    max-width: 100%;
    border-left: none;
  }
  .buy-btn { padding: 10px 16px; }
}
