:root {
  color-scheme: dark;
  --bg: #07101d;
  --bg-2: #0a1627;
  --surface: #0e1b2d;
  --surface-2: #12233a;
  --surface-3: #182b45;
  --text: #f3f7ff;
  --muted: #93a4bd;
  --line: rgba(255, 255, 255, 0.11);
  --accent: #75e9b2;
  --accent-strong: #9ef7cb;
  --accent-2: #7dc2ff;
  --warning: #ffd36a;
  --danger: #ff7d86;
  --green: #36d69b;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.34);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100vh;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 0%, rgba(67, 184, 255, 0.13), transparent 33rem),
    radial-gradient(circle at 94% 4%, rgba(117, 233, 178, 0.10), transparent 34rem),
    linear-gradient(180deg, #07101d 0%, #091426 42%, #07101d 100%);
}
button, input, textarea, select { font: inherit; }
button { touch-action: manipulation; }
[hidden] { display: none !important; }

.app-header {
  width: min(1220px, calc(100% - 2rem));
  margin: 0 auto;
  padding: max(1rem, env(safe-area-inset-top)) 0 0.6rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.app-header h1 { margin: 0; font-size: clamp(1.55rem, 4vw, 2.25rem); letter-spacing: -0.04em; }
.eyebrow { margin: 0 0 0.28rem; color: var(--accent); font-size: 0.72rem; font-weight: 900; letter-spacing: 0.14em; text-transform: uppercase; }
.subtitle { margin: 0.3rem 0 0; color: var(--muted); }
.header-actions, .button-row, .play-tools, .history-heading, .log-heading, .badge-row { display: flex; align-items: center; gap: 0.65rem; flex-wrap: wrap; }
.status-pill, .phase-badge, .trigger-badge, .strategy-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0.3rem 0.66rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.045em;
}
.status-pill { color: #bdf6dc; background: rgba(51, 206, 147, 0.12); border: 1px solid rgba(51, 206, 147, 0.26); }
.status-pill.offline { color: #ffe7a5; background: rgba(255, 211, 106, 0.10); border-color: rgba(255, 211, 106, 0.25); }
.phase-badge { color: #d7eaff; background: rgba(125, 194, 255, 0.12); border: 1px solid rgba(125, 194, 255, 0.24); }
.trigger-badge { color: #071a10; background: var(--accent); }
.strategy-badge { color: #e8dcff; background: rgba(178, 132, 255, 0.12); border: 1px solid rgba(178, 132, 255, 0.25); }

.page-shell { width: min(1220px, calc(100% - 2rem)); margin: 0.7rem auto 2rem; display: grid; gap: 0.9rem; }
.action-panel, .panel, .metric-card {
  background: linear-gradient(165deg, rgba(17, 34, 56, 0.96), rgba(10, 20, 35, 0.98));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.action-panel { border-radius: 1.15rem; padding: 1rem; overflow: hidden; position: relative; }
.action-panel::after { content: ""; position: absolute; inset: auto -5rem -7rem auto; width: 18rem; height: 18rem; border-radius: 50%; background: rgba(117, 233, 178, 0.07); pointer-events: none; }
.action-topline { display: flex; justify-content: space-between; align-items: center; gap: 0.7rem; }
.action-main { display: grid; gap: 1.15rem; align-items: center; margin-top: 0.85rem; }
.five-layout { grid-template-columns: minmax(310px, 0.95fr) 1.35fr; }
.label { margin: 0 0 0.48rem; color: var(--muted); font-size: 0.76rem; font-weight: 850; text-transform: uppercase; letter-spacing: 0.08em; }
.active-five { display: grid; grid-template-columns: repeat(5, minmax(52px, 1fr)); gap: 0.45rem; max-width: 480px; }
.active-five .number-chip { width: 100%; height: 68px; font-size: 1.45rem; }
.empty-five { display: grid; place-items: center; grid-column: 1 / -1; min-height: 68px; border: 1px dashed var(--line); border-radius: 0.9rem; color: var(--muted); font-size: 1.4rem; }
.action-copy h2 { margin: 0 0 0.48rem; font-size: clamp(1.2rem, 3vw, 1.75rem); }
.action-copy p { margin: 0; color: var(--muted); line-height: 1.5; }
.last-outcome { display: inline-block; margin-top: 0.65rem !important; padding: 0.48rem 0.68rem; border-radius: 0.65rem; background: rgba(255,255,255,0.05); border: 1px solid var(--line); color: #dce8fa !important; font-size: 0.84rem; }
.reentry-banner { margin-top: 0.72rem; padding: 0.72rem; border-radius: 0.75rem; background: rgba(255, 211, 106, 0.09); border: 1px solid rgba(255, 211, 106, 0.25); color: #ffe9aa; line-height: 1.45; font-size: 0.88rem; }

.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.7rem; }
.metric-card { min-height: 108px; border-radius: 0.95rem; padding: 0.82rem; display: flex; flex-direction: column; justify-content: space-between; box-shadow: none; }
.metric-card.emphasis { border-color: rgba(117, 233, 178, 0.32); background: linear-gradient(165deg, rgba(29, 87, 66, 0.47), rgba(10, 27, 28, 0.98)); }
.metric-card.emphasis-alt { border-color: rgba(125, 194, 255, 0.32); background: linear-gradient(165deg, rgba(32, 72, 111, 0.50), rgba(10, 24, 42, 0.98)); }
.metric-card.debt { border-color: rgba(255, 125, 134, 0.25); }
.metric-label { color: var(--muted); font-size: 0.72rem; font-weight: 850; text-transform: uppercase; letter-spacing: 0.075em; }
.metric-card strong { display: block; margin: 0.25rem 0; font-size: clamp(1.2rem, 3vw, 1.62rem); letter-spacing: -0.025em; }
.metric-card small { color: var(--muted); line-height: 1.3; }
.positive { color: var(--accent) !important; }
.negative { color: var(--danger) !important; }
.warning { color: var(--warning) !important; }

.panel { border-radius: 1rem; overflow: hidden; }
.panel summary { cursor: pointer; padding: 0.92rem 1rem; font-size: 1rem; font-weight: 900; list-style: none; }
.panel summary::-webkit-details-marker { display: none; }
.panel summary::after { content: "+"; float: right; color: var(--muted); }
.panel[open] summary::after { content: "−"; }
.details-body { padding: 0 1rem 1rem; }
.panel-heading { padding: 1rem 1rem 0.7rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.panel-heading h2 { margin: 0; }
.hint { color: var(--muted); font-size: 0.82rem; line-height: 1.45; }
.play-panel > .hint { padding: 0 1rem; margin-top: 0; }

.number-grid { padding: 0.35rem 1rem 1rem; display: grid; grid-template-columns: repeat(10, minmax(44px, 1fr)); gap: 0.48rem; }
.number-button { min-height: 52px; border: 1px solid rgba(255,255,255,0.14); border-radius: 0.75rem; color: white; font-weight: 900; font-size: 1rem; cursor: pointer; transition: transform 120ms ease, filter 120ms ease, border-color 120ms ease, box-shadow 120ms ease; }
.number-button:hover { filter: brightness(1.14); border-color: rgba(255,255,255,0.65); }
.number-button:active { transform: scale(0.95); }
.number-button.red { background: linear-gradient(145deg, #c54058, #812638); }
.number-button.black { background: linear-gradient(145deg, #30394c, #101621); }
.number-button.green { background: linear-gradient(145deg, #1d9a70, #0b533b); }
.number-button.active-target { box-shadow: 0 0 0 3px rgba(255, 211, 106, 0.88), 0 0 22px rgba(255, 211, 106, 0.26); border-color: #fff0b1; }

.number-chip { display: inline-grid; place-items: center; min-width: 34px; height: 34px; padding: 0 0.42rem; border-radius: 999px; color: white; font-weight: 900; border: 1px solid rgba(255,255,255,0.15); }
.number-chip.red { background: #a62d46; }
.number-chip.black { background: #202b3c; }
.number-chip.green { background: #16835d; }
.history-block { padding: 0 1rem 1rem; }
.history-heading { justify-content: space-between; }
.history-heading h3 { margin: 0; }
.history-heading span { color: var(--muted); font-size: 0.8rem; }
.history-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.7rem; }
.history-chips .number-chip { min-width: 31px; height: 31px; font-size: 0.84rem; }

.button { min-height: 40px; padding: 0.62rem 0.86rem; border-radius: 0.72rem; border: 1px solid transparent; font-weight: 850; cursor: pointer; }
.button:disabled { opacity: 0.45; cursor: not-allowed; }
.button.primary { color: #04150d; background: var(--accent); }
.button.primary:hover { background: var(--accent-strong); }
.button.secondary { color: var(--text); background: var(--surface-3); border-color: var(--line); }
.button.ghost { color: var(--muted); background: transparent; border-color: var(--line); }
.button.danger { color: #ffdede; background: rgba(255, 114, 114, 0.13); border-color: rgba(255, 114, 114, 0.35); }
.button.wide { width: 100%; margin-top: 0.9rem; }
.button-row.compact .button { min-height: 34px; padding: 0.45rem 0.65rem; font-size: 0.85rem; }

.switch-label, .checkbox-label { display: inline-flex; align-items: center; gap: 0.45rem; color: var(--muted); font-size: 0.9rem; }
.switch-label input:checked + span { color: var(--warning); font-weight: 850; }
.import-layout { display: grid; grid-template-columns: 1.45fr 1fr; gap: 1rem; }
.form-row, .settings-grid, .money-settings, .setup-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.8rem; margin: 0.8rem 0; }
.progression-settings { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.money-settings { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.setup-grid { margin: 0.9rem 0; }
.full-width { grid-column: 1 / -1; }
label { display: grid; gap: 0.38rem; color: var(--muted); font-size: 0.85rem; font-weight: 750; }
input, textarea, select { width: 100%; color: var(--text); background: #08111f; border: 1px solid var(--line); border-radius: 0.72rem; padding: 0.72rem 0.78rem; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(117, 233, 178, 0.10); }
textarea { resize: vertical; line-height: 1.5; }
.strategy-description { padding: 0.78rem; border-radius: 0.78rem; background: rgba(125, 194, 255, 0.08); border: 1px solid rgba(125, 194, 255, 0.20); color: #d2eaff; line-height: 1.45; }
.photo-preview-wrap { margin-top: 0.75rem; }
.photo-preview-wrap img { display: block; width: 100%; max-height: 340px; object-fit: contain; background: #050810; border: 1px solid var(--line); border-radius: 0.8rem; transform-origin: center; margin-bottom: 0.65rem; }
.photo-preview-wrap img.rotate-0 { transform: rotate(0deg); }
.photo-preview-wrap img.rotate-90 { transform: rotate(90deg); }
.photo-preview-wrap img.rotate-180 { transform: rotate(180deg); }
.photo-preview-wrap img.rotate-270 { transform: rotate(270deg); }

.diagnostic-summary { padding: 0.8rem; border-radius: 0.8rem; background: rgba(125, 194, 255, 0.08); border: 1px solid rgba(125, 194, 255, 0.20); color: #d2eaff; margin-bottom: 0.8rem; line-height: 1.5; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
th, td { padding: 0.62rem; border-bottom: 1px solid var(--line); text-align: right; font-size: 0.84rem; }
th { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; }
th:nth-child(2), td:nth-child(2), th:last-child, td:last-child { text-align: left; }
tr.top-five { background: rgba(117, 233, 178, 0.06); }
tr.leader-row { background: rgba(117, 233, 178, 0.14); }
.progression-table { min-width: 820px; }
.progression-table th:nth-child(2), .progression-table td:nth-child(2) { text-align: left; }
.progression-table tr.current-row { background: rgba(255, 211, 106, 0.15); box-shadow: inset 3px 0 0 var(--warning); }
.progression-table tr.reentry-match { background: rgba(125, 194, 255, 0.10); }
.progression-table td.result-positive { color: var(--accent); font-weight: 850; }
.progression-table td.result-negative { color: var(--danger); }

.file-button { display: inline-flex; width: auto; }
.log-heading { justify-content: space-between; margin-top: 1rem; }
.log-heading h3 { margin: 0; }
.event-log { display: grid; gap: 0.55rem; margin-top: 0.7rem; max-height: 440px; overflow: auto; }
.log-entry { padding: 0.7rem; border-radius: 0.72rem; background: #081321; border: 1px solid var(--line); }
.log-entry strong { display: block; margin-bottom: 0.2rem; font-size: 0.78rem; color: var(--accent); }
.log-entry p { margin: 0; color: #dbe4f4; font-size: 0.86rem; line-height: 1.38; }
.log-entry time { display: block; color: var(--muted); font-size: 0.72rem; margin-top: 0.25rem; }
.empty { color: var(--muted); }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 1rem; background: rgba(2, 7, 14, 0.82); backdrop-filter: blur(10px); }
.modal-card { width: min(680px, 100%); max-height: calc(100vh - 2rem); overflow: auto; padding: 1.2rem; border-radius: 1.1rem; background: linear-gradient(165deg, #13253d, #091423); border: 1px solid rgba(255,255,255,0.15); box-shadow: 0 30px 90px rgba(0,0,0,0.55); }
.modal-card h2 { margin: 0; font-size: 1.65rem; }
.modal-intro { color: var(--muted); line-height: 1.5; }

footer { width: min(1220px, calc(100% - 2rem)); margin: 0 auto 2rem; color: var(--muted); font-size: 0.8rem; text-align: center; }
.toast { position: fixed; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); z-index: 150; transform: translateX(-50%); width: min(92vw, 560px); padding: 0.85rem 1rem; border-radius: 0.85rem; background: #eefbf5; color: #092015; box-shadow: var(--shadow); font-weight: 780; text-align: center; }
.toast.error { background: #ffe7e7; color: #4c1111; }

@media (max-width: 1000px) {
  .metrics-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .number-grid { grid-template-columns: repeat(8, minmax(42px, 1fr)); }
  .progression-settings { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-header { align-items: flex-start; }
  .subtitle { display: none; }
  .page-shell { width: min(100% - 1rem, 1220px); margin-top: 0.55rem; }
  .five-layout { grid-template-columns: 1fr; }
  .active-five { max-width: none; }
  .active-five .number-chip { height: 58px; font-size: 1.2rem; }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.55rem; }
  .metric-card { min-height: 98px; padding: 0.72rem; }
  .number-grid { grid-template-columns: repeat(6, minmax(42px, 1fr)); gap: 0.42rem; }
  .number-button { min-height: 48px; }
  .import-layout, .form-row, .settings-grid, .money-settings, .setup-grid, .progression-settings { grid-template-columns: 1fr; }
  .panel-heading { align-items: flex-start; flex-direction: column; }
  .play-tools { width: 100%; justify-content: space-between; }
  .action-topline { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 420px) {
  .number-grid { grid-template-columns: repeat(5, minmax(42px, 1fr)); }
  .active-five { grid-template-columns: repeat(5, minmax(44px, 1fr)); gap: 0.3rem; }
  .active-five .number-chip { height: 52px; padding: 0; }
}
