:root {
  --bg: #eef6ff;
  --bg-2: #f7fbff;
  --panel: #ffffff;
  --line: rgba(20, 70, 140, 0.14);
  --text: #10233d;
  --muted: #5d7391;
  --accent: #0b8a4a;
  --accent-2: #1677d6;
  --pitch: #1f9d55;
  --good: #0b8a4a;
  --warn: #c47b00;
  --danger: #d64555;
  --shadow: 0 10px 28px rgba(24, 55, 99, 0.1);
  --radius: 20px;
  --font: "IBM Plex Sans Arabic", sans-serif;
  --digits: "Russo One", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow-x: hidden;
}

.app-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(700px 320px at 100% 0%, rgba(22, 119, 214, 0.14), transparent 60%),
    radial-gradient(560px 280px at 0% 100%, rgba(31, 157, 85, 0.14), transparent 55%),
    linear-gradient(180deg, #eef6ff 0%, #f8fbff 55%, #eef7f1 100%);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.1rem 1.25rem 0.4rem;
}

.game-badge {
  margin: 0 0 0.25rem;
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #0b5c32;
  background: rgba(31, 157, 85, 0.12);
  border: 1px solid rgba(31, 157, 85, 0.25);
  border-radius: 999px;
  padding: 0.18rem 0.6rem;
}

.brand {
  margin: 0;
  font-size: clamp(1.7rem, 6vw, 2.3rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.brand-sub {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.45rem;
}

.icon-btn {
  min-width: 52px;
  height: 40px;
  padding: 0 0.55rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
}

.icon-btn:active { opacity: 0.85; }

.main {
  padding: 0.6rem 1.25rem 6rem;
  max-width: 760px;
  margin: 0 auto;
}

.login-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login-screen[hidden],
#appShell[hidden] { display: none !important; }

.login-card {
  width: min(100%, 390px);
  padding: 1.4rem;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
}

.login-card .field { text-align: right; }
.login-card .brand-sub { margin-bottom: 1.1rem; }

.login-error {
  color: var(--danger);
  margin: -0.3rem 0 0.8rem;
  font-size: 0.92rem;
}

.sync-bar {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.85rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9aaec6;
}

.sync-dot.ok { background: var(--good); }
.sync-dot.warn { background: var(--warn); }
.sync-dot.err { background: var(--danger); }

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
  margin-bottom: 0.9rem;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  padding: 0.8rem 0.7rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 0.3rem;
}

.stat-card strong {
  color: var(--accent-2);
  font-size: 1.05rem;
}

.stat-card.debt strong { color: var(--danger); }

.section-title {
  margin: 0 0 0.7rem;
  font-size: 1.05rem;
  color: var(--muted);
  font-weight: 600;
}

.rate-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 0.9rem;
  padding: 0.5rem 0.85rem;
  border: 1px solid rgba(22, 119, 214, 0.2);
  border-radius: 999px;
  background: rgba(22, 119, 214, 0.08);
  color: var(--muted);
}

.rate-chip strong {
  color: var(--accent-2);
  font-size: 1.02rem;
}

.stations {
  display: grid;
  gap: 0.75rem;
}

.station-card {
  width: 100%;
  text-align: right;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: inherit;
  padding: 1rem 1.05rem;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem 0.9rem;
  align-items: center;
}

.station-card.running { border-color: rgba(31, 157, 85, 0.45); }
.station-card.paused { border-color: rgba(196, 123, 0, 0.4); }
.station-card.ended { border-color: rgba(214, 69, 85, 0.45); }

.station-card h3 { margin: 0; font-size: 1.15rem; }
.station-meta { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.9rem; }

.station-time {
  font-family: var(--digits);
  font-size: 1.25rem;
  color: var(--accent-2);
  letter-spacing: 0.03em;
}

.station-badge {
  grid-column: 1 / -1;
  justify-self: start;
  font-size: 0.78rem;
  color: var(--good);
  background: rgba(31, 157, 85, 0.1);
  border: 1px solid rgba(31, 157, 85, 0.22);
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
}

.station-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.station-actions .btn.sm {
  padding: 0.7rem 0.6rem;
  font-size: 0.92rem;
  border-radius: 12px;
}

.station-card.idle .station-actions,
.station-card.ended .station-actions {
  grid-template-columns: 1fr;
}

.station-card.paused .station-badge { color: var(--warn); background: rgba(196,123,0,0.1); border-color: rgba(196,123,0,0.25); }
.station-card.ended .station-badge { color: var(--danger); background: rgba(214,69,85,0.1); border-color: rgba(214,69,85,0.25); }
.station-card.idle .station-badge { color: var(--muted); background: #f3f7fc; border-color: var(--line); }

.fab {
  position: fixed;
  left: 50%;
  bottom: calc(1.15rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  border: 0;
  border-radius: 999px;
  padding: 0.85rem 1.25rem;
  background: linear-gradient(135deg, var(--pitch), var(--accent-2));
  color: #fff;
  font: inherit;
  font-weight: 700;
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 20;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(16, 35, 61, 0.4);
}

.sheet-backdrop[hidden] { display: none !important; }

.sheet {
  width: min(100%, 520px);
  max-height: min(92dvh, 860px);
  border: 1px solid var(--line);
  border-radius: 28px 28px 0 0;
  background: var(--panel);
  color: var(--text);
  padding: 0;
  box-shadow: var(--shadow);
  position: fixed;
  left: 50%;
  right: auto;
  bottom: 0;
  transform: translateX(-50%);
  z-index: 30;
  overflow: auto;
}

.sheet[hidden] { display: none !important; }

.sheet-inner {
  padding: 1.1rem 1.15rem 1.4rem;
  overflow: auto;
}

.sheet-head { margin-bottom: 0.9rem; }
.sheet-head h2 { margin: 0; font-size: 1.3rem; }
.sheet-head p { margin: 0.25rem 0 0; color: var(--muted); }

.timer-face {
  display: grid;
  place-items: center;
  margin: 0.35rem 0 1.1rem;
}

.timer-ring {
  width: min(100%, 280px);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-content: center;
  gap: 0.3rem;
  text-align: center;
  background:
    radial-gradient(circle at center, #ffffff 57%, transparent 58%),
    repeating-linear-gradient(0deg, rgba(31,157,85,0.18) 0 2px, transparent 2px 14px),
    linear-gradient(145deg, #1f9d55, #1677d6);
  border: 4px solid #dcecff;
  box-shadow: inset 0 0 0 10px rgba(255,255,255,0.35), var(--shadow);
}

.timer-game {
  font-size: 0.78rem;
  font-weight: 700;
  color: #0b5c32;
  letter-spacing: 0.03em;
}

.timer-digits {
  font-family: var(--digits);
  font-size: clamp(1.7rem, 7vw, 2.3rem);
  color: #0f2a4a;
  letter-spacing: 0.04em;
}

.timer-cost {
  color: var(--good);
  font-weight: 700;
  font-size: 1.1rem;
}

.field, .field-row {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
}

.field span, .pay-methods legend {
  color: var(--muted);
  font-size: 0.9rem;
}

.field input,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8fbff;
  color: var(--text);
  padding: 0.8rem 0.9rem;
  font: inherit;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: rgba(22, 119, 214, 0.55);
  box-shadow: 0 0 0 3px rgba(22, 119, 214, 0.12);
}

.report-box {
  margin: 0 0 1rem;
  padding: 0.9rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #f7fafc;
  color: #122033;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font);
  font-size: 0.92rem;
  line-height: 1.55;
  max-height: 50dvh;
  overflow: auto;
}

.actions {
  display: grid;
  gap: 0.6rem;
  margin-top: 0.45rem;
}

.btn {
  border: 0;
  border-radius: 14px;
  padding: 0.9rem 1rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.btn:active { opacity: 0.9; }
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn.primary {
  background: linear-gradient(135deg, var(--pitch), var(--accent-2));
  color: #fff;
}
.btn.ghost {
  background: #f3f7fc;
  color: var(--text);
  border: 1px solid var(--line);
}
.btn.danger {
  background: rgba(214, 69, 85, 0.1);
  color: #a52233;
  border: 1px solid rgba(214, 69, 85, 0.3);
}
.btn.warn {
  background: rgba(196, 123, 0, 0.12);
  color: #8a5600;
  border: 1px solid rgba(196, 123, 0, 0.3);
}
.btn.back {
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--line);
}

.hint {
  margin: -0.45rem 0 0.85rem;
  color: var(--warn);
  font-size: 0.88rem;
}

.alert-banner {
  position: fixed;
  top: calc(0.7rem + env(safe-area-inset-top));
  left: 0.7rem;
  right: 0.7rem;
  z-index: 40;
  display: flex;
  justify-content: space-between;
  gap: 0.7rem;
  align-items: center;
  padding: 0.85rem 1rem;
  border-radius: 16px;
  border: 1px solid rgba(214, 69, 85, 0.35);
  background: #fff5f6;
  box-shadow: var(--shadow);
}

.alert-banner[hidden] { display: none !important; }
.alert-banner strong { display: block; color: #a52233; }
.alert-banner p { margin: 0.15rem 0 0; color: #b54755; font-size: 0.9rem; }
.alert-banner .btn { flex-shrink: 0; padding: 0.5rem 0.8rem; }

.pay-summary {
  display: grid;
  gap: 0.65rem;
  margin-bottom: 0.9rem;
  padding: 0.95rem;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #f8fbff;
}

.pay-summary > div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
}

.pay-summary strong { color: var(--text); }

.pay-methods {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.8rem 1rem 0.95rem;
  margin: 0 0 0.9rem;
  display: grid;
  gap: 0.5rem;
  background: #fff;
}

.pay-methods label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.invoice {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
  background: #fff;
  color: #122033;
  margin-bottom: 0.9rem;
}

.invoice.debt-invoice {
  border-color: rgba(214, 69, 85, 0.35);
  background: #fff8f8;
}

.invoice h3 { margin: 0 0 0.3rem; font-size: 1.2rem; }
.invoice .muted { color: #5b6b80; margin: 0 0 0.75rem; font-size: 0.88rem; }

.invoice table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.4rem 0 0.75rem;
}

.invoice td {
  padding: 0.4rem 0;
  border-bottom: 1px solid #e4ebf3;
  font-size: 0.92rem;
}

.invoice td:last-child { text-align: left; font-weight: 600; }

.invoice .grand {
  display: flex;
  justify-content: space-between;
  font-size: 1.1rem;
  font-weight: 700;
  margin-top: 0.4rem;
}

.history-list { display: grid; gap: 0.65rem; }

.history-item {
  width: 100%;
  text-align: right;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: inherit;
  padding: 0.85rem 0.95rem;
  cursor: pointer;
  font: inherit;
}

.history-item.debt { border-color: rgba(214, 69, 85, 0.3); background: #fff8f8; }
.history-item strong { display: block; margin-bottom: 0.15rem; }
.history-item span { display: block; color: var(--muted); font-size: 0.88rem; margin-top: 0.15rem; }

.invoice-row {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  padding: 0.85rem;
  display: grid;
  gap: 0.65rem;
}

.invoice-row.debt {
  border-color: rgba(214, 69, 85, 0.3);
  background: #fff8f8;
}

.invoice-row-main strong {
  display: block;
  margin-bottom: 0.2rem;
}

.invoice-row-main span {
  display: block;
  color: var(--muted);
  font-size: 0.88rem;
}

.invoice-row-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}

.invoice-row-actions .btn.sm {
  padding: 0.55rem 0.35rem;
  font-size: 0.85rem;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 1.6rem 1rem;
}

@media (min-width: 720px) {
  .sheet {
    bottom: auto;
    top: 50%;
    transform: translate(-50%, -50%);
    border-radius: 24px;
  }
  .stats { grid-template-columns: repeat(4, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
