:root {
  --bg-top: #0a2540;
  --bg-bottom: #0d3b5c;
  --aqua: #3dd6d0;
  --aqua-deep: #1a9e98;
  --foam: #e8fbfa;
  --ink: #07202f;
  --card: #0f3550;
  --card-soft: #14425f;
  --line: rgba(61, 214, 208, 0.22);
  --warn: #ff7a7a;
  --gold: #ffd86b;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: "Fredoka", system-ui, sans-serif;
  color: var(--foam);
  background: linear-gradient(160deg, var(--bg-top), var(--bg-bottom) 60%, #06263d);
  background-attachment: fixed;
  line-height: 1.5;
  overflow-x: hidden;
  position: relative;
}

/* floating bubbles */
.bubbles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.bubbles span {
  position: absolute;
  bottom: -60px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.45), rgba(61,214,208,0.12));
  border: 1px solid rgba(255,255,255,0.18);
  animation: rise linear infinite;
}
@keyframes rise {
  to { transform: translateY(-110vh) translateX(var(--drift, 0)); opacity: 0; }
}

main, .site-header, .site-footer { position: relative; z-index: 1; }

/* header */
.site-header {
  text-align: center;
  padding: 48px 20px 12px;
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 2.6rem;
  font-weight: 700;
}
.logo-drop { animation: wobble 3s ease-in-out infinite; }
@keyframes wobble {
  0%, 100% { transform: rotate(-6deg) translateY(0); }
  50% { transform: rotate(6deg) translateY(-4px); }
}
.logo-text { letter-spacing: -0.5px; }
.tm { font-size: 1rem; vertical-align: super; color: var(--aqua); }
.tagline { margin: 6px 0 0; color: var(--aqua); font-weight: 500; }
.fineprint { margin: 2px 0 0; font-size: 0.8rem; opacity: 0.55; font-family: "Space Mono", monospace; }

main {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 18px 40px;
  display: grid;
  gap: 22px;
}

/* cards */
.card {
  background: linear-gradient(180deg, var(--card), var(--card-soft));
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 28px 26px;
  box-shadow: var(--shadow);
}

/* live dashboard */
.live-board {
  background: linear-gradient(180deg, #103a2e, #0d4632);
  border-color: rgba(255, 216, 107, 0.25);
}
.live-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.live-head h2 { margin: 0; font-size: 1.4rem; }
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(255, 122, 122, 0.16);
  border: 1px solid rgba(255, 122, 122, 0.4);
  color: #ff9a9a;
  font-family: "Space Mono", monospace;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 5px 11px;
  border-radius: 999px;
}
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff5a5a;
  box-shadow: 0 0 0 0 rgba(255, 90, 90, 0.7);
  animation: pulse 1.6s infinite;
}
.live-badge.offline { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.2); color: rgba(255,255,255,0.55); }
.live-badge.offline .live-dot { background: #888; animation: none; box-shadow: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 90, 90, 0.6); }
  70% { box-shadow: 0 0 0 9px rgba(255, 90, 90, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 90, 90, 0); }
}
.live-sub { margin: 6px 0 20px; opacity: 0.78; font-size: 0.92rem; }
.live-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.live-stat {
  background: rgba(7, 32, 47, 0.4);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 10px;
  text-align: center;
}
.live-stat.headline { border-color: rgba(255, 216, 107, 0.4); background: rgba(255, 216, 107, 0.08); }
.live-icon { font-size: 1.6rem; }
.live-value {
  font-family: "Space Mono", monospace;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--gold);
  margin: 6px 0 2px;
  word-break: break-word;
  transition: transform 0.2s;
}
.live-value.bump { transform: scale(1.18); }
.live-label { font-size: 0.76rem; opacity: 0.72; }
.live-ticker {
  margin-top: 18px;
  padding: 11px 14px;
  background: rgba(7, 32, 47, 0.55);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 0.88rem;
  display: flex;
  gap: 8px;
  align-items: baseline;
}
.ticker-label { font-family: "Space Mono", monospace; color: var(--aqua); font-weight: 700; font-size: 0.78rem; flex: 0 0 auto; }
.ticker-msg { opacity: 0.9; }
.ticker-msg.flash { animation: tickerflash 1.4s; }
@keyframes tickerflash {
  0% { color: var(--gold); }
  100% { color: inherit; }
}

h1 {
  margin: 0 0 6px;
  font-size: 1.7rem;
  line-height: 1.25;
}
.subject-name { color: var(--aqua); }
.subhead { margin: 0 0 22px; opacity: 0.8; }

/* form */
.field { margin-bottom: 20px; }
label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 0.95rem;
}
.muted { opacity: 0.55; font-weight: 400; font-size: 0.85rem; }

input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 13px 15px;
  background: rgba(7, 32, 47, 0.6);
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--foam);
  font-family: inherit;
  font-size: 1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--aqua);
  box-shadow: 0 0 0 3px rgba(61, 214, 208, 0.18);
}
select { cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%233dd6d0'%3E%3Cpath d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 15px center;
  padding-right: 38px;
}

.count-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.count-row input { flex: 1 1 120px; }
.quick-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: rgba(61, 214, 208, 0.12);
  border: 1px solid var(--line);
  color: var(--aqua);
  border-radius: 10px;
  padding: 9px 12px;
  font-family: "Space Mono", monospace;
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}
.chip:hover { background: rgba(61, 214, 208, 0.22); }
.chip:active { transform: scale(0.94); }
.chip.danger { color: var(--warn); border-color: rgba(255,122,122,0.4); background: rgba(255,122,122,0.1); }

.calc-btn {
  width: 100%;
  margin-top: 6px;
  padding: 16px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(120deg, var(--aqua), var(--aqua-deep));
  color: var(--ink);
  font-family: inherit;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(61, 214, 208, 0.3);
  transition: transform 0.1s, box-shadow 0.15s, filter 0.15s;
}
.calc-btn:hover { filter: brightness(1.05); box-shadow: 0 14px 30px rgba(61, 214, 208, 0.4); }
.calc-btn:active { transform: translateY(2px) scale(0.99); }
.calc-btn[disabled] { filter: grayscale(0.4) brightness(0.9); cursor: wait; }
.btn-spinner { font-family: "Space Mono", monospace; font-size: 0.95rem; }

.status { min-height: 1.2em; margin: 12px 0 0; font-size: 0.9rem; color: var(--warn); text-align: center; }

/* results */
.results { animation: pop 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.3); }
@keyframes pop {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
.results h2 { margin: 0 0 4px; font-size: 1.5rem; }
.verdict-emoji { font-size: 1.3rem; }
.verdict-line { margin: 0 0 22px; font-size: 1.05rem; color: var(--gold); font-weight: 500; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}
.stat {
  background: rgba(7, 32, 47, 0.5);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 12px;
  text-align: center;
}
.stat-icon { font-size: 1.9rem; }
.stat-value {
  font-family: "Space Mono", monospace;
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--aqua);
  margin: 6px 0 2px;
  word-break: break-word;
}
.stat-unit { font-size: 0.8rem; opacity: 0.75; }
.stat-context { font-size: 0.78rem; opacity: 0.6; margin-top: 8px; font-style: italic; min-height: 2.4em; }

/* receipt */
.receipt {
  background: #f6f4ec;
  color: #1c1c1c;
  border-radius: 10px;
  padding: 20px 18px;
  font-family: "Space Mono", monospace;
  font-size: 0.82rem;
  margin-bottom: 20px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);
  position: relative;
}
.receipt-header, .receipt-footer { text-align: center; font-weight: 700; }
.receipt-footer { margin-top: 12px; opacity: 0.7; font-weight: 400; }
.receipt-rows { margin: 14px 0; border-top: 1px dashed #999; border-bottom: 1px dashed #999; padding: 10px 0; }
.receipt-line { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.receipt-line .r-val { font-weight: 700; }

.results-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.ghost-btn {
  flex: 1 1 140px;
  padding: 13px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--foam);
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.ghost-btn:hover { background: rgba(61, 214, 208, 0.1); border-color: var(--aqua); }

/* footer */
.site-footer {
  text-align: center;
  padding: 24px 20px 50px;
  max-width: 600px;
  margin: 0 auto;
  font-size: 0.85rem;
  opacity: 0.7;
}
.disclaimer { font-family: "Space Mono", monospace; font-size: 0.78rem; margin-top: 8px; }
#backend-mode { color: var(--aqua); }

/* oath modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 18, 30, 0.72);
  backdrop-filter: blur(4px);
  animation: fadein 0.18s ease;
}
.modal-overlay[hidden] { display: none; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  width: 100%;
  max-width: 430px;
  background: #f3ead2;
  color: #2a2113;
  border-radius: 16px;
  padding: 30px 28px 26px;
  text-align: center;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  border: 1px solid #d8c89a;
  font-family: "Fredoka", sans-serif;
  animation: pop 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.3);
  background-image:
    radial-gradient(circle at 18% 22%, rgba(150, 120, 60, 0.12), transparent 45%),
    radial-gradient(circle at 82% 78%, rgba(150, 120, 60, 0.12), transparent 45%);
}
.modal-seal {
  font-size: 2.4rem;
  width: 64px;
  height: 64px;
  margin: 0 auto 8px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(120, 80, 30, 0.12);
  border: 2px dashed #b89b5e;
}
.modal-card h3 {
  margin: 6px 0 10px;
  font-size: 1.5rem;
  color: #3a2d12;
}
.modal-body { margin: 0 0 16px; font-size: 0.96rem; opacity: 0.85; line-height: 1.5; }
.modal-oath {
  margin: 0 0 22px;
  font-family: "Space Mono", monospace;
  font-size: 1.05rem;
  font-weight: 700;
  color: #5a3d12;
  padding: 14px 16px;
  border-top: 1px dashed #b89b5e;
  border-bottom: 1px dashed #b89b5e;
}
.modal-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.modal-btn {
  flex: 1 1 140px;
  padding: 13px 14px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s, background 0.15s;
}
.modal-btn:active { transform: scale(0.97); }
.modal-btn.confirm {
  border: none;
  background: linear-gradient(120deg, #b5832e, #8a5e16);
  color: #fff6e2;
  box-shadow: 0 8px 20px rgba(138, 94, 22, 0.4);
}
.modal-btn.confirm:hover { filter: brightness(1.07); }
.modal-btn.cancel {
  background: transparent;
  border: 1px solid #b89b5e;
  color: #5a3d12;
}
.modal-btn.cancel:hover { background: rgba(120, 80, 30, 0.08); }

@media (max-width: 540px) {
  .stat-grid, .live-grid { grid-template-columns: 1fr; }
  h1 { font-size: 1.4rem; }
  .logo { font-size: 2.1rem; }
}
