:root {
  color-scheme: light;
  --canvas: #f1f3f0;
  --surface: #ffffff;
  --ink: #1d2522;
  --muted: #68726e;
  --line: #d8ded9;
  --green: #276451;
  --red: #b4403a;
  --blue: #2e6ea6;
  --gold: #a67525;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-width: 320px; min-height: 100%; margin: 0; }
body { min-height: 100vh; display: grid; grid-template-rows: auto 1fr auto; background: var(--canvas); color: var(--ink); letter-spacing: 0; }
button, input, select { font: inherit; }
a, button { -webkit-tap-highlight-color: transparent; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(39, 100, 81, .22); outline-offset: 2px; }

.topbar { min-height: 70px; padding: 0 max(24px, env(safe-area-inset-right)) 0 max(24px, env(safe-area-inset-left)); display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, .95); }
.brand { display: inline-flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 6px; background: #263631; color: #f2cc69; font-weight: 850; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { margin-top: 1px; color: var(--muted); font-size: 9px; font-weight: 700; }
.header-actions { display: flex; align-items: center; gap: 9px; }
.icon-button, .home-link { min-height: 38px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
.icon-button { width: 38px; padding: 0; cursor: pointer; font-size: 18px; }
.home-link { padding: 0 12px; display: inline-flex; align-items: center; gap: 7px; text-decoration: none; font-size: 12px; font-weight: 750; }

main { width: min(1120px, calc(100% - 48px)); margin: 0 auto; padding: 54px 0 70px; }
.intro { margin-bottom: 24px; display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; }
.intro > p { margin: 0 0 4px; color: var(--muted); font-size: 12px; }
.eyebrow { margin: 0 0 6px; color: var(--green); font-size: 10px; font-weight: 850; }
h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 34px; }
h2 { font-size: 19px; }

.workbench { display: grid; grid-template-columns: 330px minmax(0, 1fr); align-items: stretch; gap: 16px; }
.control-panel, .result-panel { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 10px 28px rgba(29, 37, 34, .05); }
.control-panel { padding: 24px; }
.field + .field { margin-top: 18px; }
.field label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 800; }
.field select { width: 100%; height: 44px; padding: 0 36px 0 12px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); font-size: 13px; }
.pick-mode { min-width: 0; margin: 18px 0 0; padding: 0; border: 0; }
.pick-mode legend { margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 800; }
.segmented-control { height: 42px; padding: 3px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; border: 1px solid var(--line); border-radius: 6px; background: #f2f4f2; }
.segmented-control label { min-width: 0; cursor: pointer; }
.segmented-control input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.segmented-control span { height: 34px; display: grid; place-items: center; border-radius: 4px; color: var(--muted); font-size: 11px; font-weight: 800; }
.segmented-control input:checked + span { background: #fff; color: var(--green); box-shadow: 0 1px 5px rgba(29, 37, 34, .1); }
.segmented-control input:disabled + span { cursor: wait; opacity: .45; }
.analysis-options { margin-top: 12px !important; }
.mode-status { min-height: 16px; margin: 7px 0 0; color: var(--muted); font-size: 9px; line-height: 1.5; }
.play-fields { margin-top: 18px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.play-fields:empty { display: none; }
.play-fields .field { min-width: 0; margin: 0; }
.play-fields .field label { min-height: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stepper { height: 44px; display: grid; grid-template-columns: 44px 1fr 44px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.stepper button { border: 0; background: #f5f6f4; color: var(--ink); cursor: pointer; font-size: 20px; }
.stepper button:first-child { border-right: 1px solid var(--line); }
.stepper button:last-child { border-left: 1px solid var(--line); }
.stepper input { width: 100%; border: 0; background: #fff; color: var(--ink); text-align: center; font-size: 14px; font-weight: 800; appearance: textfield; }
.stepper input::-webkit-inner-spin-button { appearance: none; }
.rule-block { min-height: 112px; margin-top: 20px; padding: 14px; border-left: 3px solid var(--gold); background: #faf8f2; }
.rule-block span, .rule-block strong, .rule-block small { display: block; }
.rule-block span { color: var(--gold); font-size: 10px; font-weight: 850; }
.rule-block strong { margin-top: 7px; font-size: 12px; line-height: 1.55; }
.rule-block small { margin-top: 5px; color: var(--muted); font-size: 10px; line-height: 1.5; }
.cost-summary { margin-top: 14px; padding: 12px 14px; display: grid; gap: 4px; border: 1px solid #d9e3de; border-radius: 6px; background: #f4f8f6; }
.cost-summary span { color: var(--muted); font-size: 10px; }
.cost-summary strong { color: var(--green); font-size: 12px; }
.cost-summary small { color: #7a857f; font-size: 9px; }
.form-error { margin: 9px 0 0; color: #a43732; font-size: 10px; line-height: 1.5; }
.generate-button { width: 100%; min-height: 46px; margin-top: 18px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--green); border-radius: 6px; background: var(--green); color: #fff; cursor: pointer; font-size: 13px; font-weight: 800; }
.generate-button:disabled { cursor: not-allowed; opacity: .5; }
.generate-button svg, .icon-command svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.result-panel { min-height: 480px; overflow: hidden; }
.panel-header, .section-header { min-height: 76px; padding: 16px 18px 16px 22px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.icon-command { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); cursor: pointer; }
.icon-command:disabled, .text-command:disabled { cursor: default; opacity: .42; }
.empty-state { min-height: 402px; display: grid; place-content: center; justify-items: center; color: var(--muted); text-align: center; }
.empty-state > span { width: 58px; height: 58px; display: grid; place-items: center; border: 2px dashed #b9c2bd; border-radius: 50%; font-size: 17px; font-weight: 850; }
.empty-state strong { margin-top: 14px; color: var(--ink); font-size: 15px; }
.empty-state p { margin: 5px 0 0; font-size: 11px; }
.ticket-list { margin: 0; padding: 8px 22px 18px; list-style: none; }
.ticket-list li { min-height: 74px; display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; align-items: center; gap: 14px; border-bottom: 1px solid #eaedea; }
.ticket-order { color: #919a95; font-size: 11px; font-variant-numeric: tabular-nums; }
.ticket-groups { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 18px; }
.number-group { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.group-label { margin-right: 2px; color: var(--muted); font-size: 10px; }
.number-ball { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 50%; color: #fff; font-size: 11px; font-weight: 850; font-variant-numeric: tabular-nums; }
.number-ball.red { background: var(--red); }
.number-ball.blue { background: var(--blue); }
.number-ball.gold { background: var(--gold); }
.number-ball.red.light { border: 2px solid var(--red); background: #fff; color: var(--red); }
.number-ball.blue.light { border: 2px solid var(--blue); background: #fff; color: var(--blue); }
.entry-bets { min-width: 86px; color: var(--muted); font-size: 10px; text-align: right; white-space: nowrap; }

.analysis-section, .history-section { margin-top: 18px; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.section-header small { display: block; margin-top: 4px; color: var(--muted); font-size: 9px; font-weight: 500; }
.text-command { min-height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: #9a3e39; cursor: pointer; font-size: 11px; font-weight: 750; }
.text-command.neutral { color: var(--ink); }
.analysis-loading, .analysis-error { min-height: 140px; padding: 42px 24px; display: grid; place-items: center; color: var(--muted); font-size: 12px; text-align: center; }
.analysis-error { color: #9a3e39; }
.analysis-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.metric { min-width: 0; padding: 17px 20px; border-right: 1px solid #eaedea; }
.metric:nth-child(3n) { border-right: 0; }
.metric:nth-child(-n+3) { border-bottom: 1px solid #eaedea; }
.metric span, .metric strong { display: block; }
.metric span { color: var(--muted); font-size: 9px; }
.metric strong { margin-top: 5px; overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.frequency-panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.frequency-panel { min-width: 0; padding: 20px 22px; border-bottom: 1px solid #eaedea; }
.frequency-panel:nth-child(odd) { border-right: 1px solid #eaedea; }
.frequency-panel header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.frequency-panel header strong { font-size: 13px; }
.frequency-panel header span { color: var(--muted); font-size: 9px; }
.stat-line { margin-top: 14px; display: grid; grid-template-columns: 58px minmax(0, 1fr); align-items: start; gap: 8px; }
.stat-line > span { padding-top: 5px; color: var(--muted); font-size: 9px; }
.stat-values { display: flex; flex-wrap: wrap; gap: 5px; }
.stat-chip { min-width: 36px; height: 26px; padding: 0 7px; display: inline-grid; place-items: center; border: 1px solid var(--line); border-radius: 4px; background: #f7f8f6; color: var(--ink); font-size: 10px; font-weight: 800; }
.stat-chip.hot { border-color: #e6c5c2; background: #fbf3f2; color: var(--red); }
.stat-chip.overdue { border-color: #d8cba9; background: #faf7ee; color: #86601e; }
.recent-draws { padding: 20px 22px 24px; }
.subsection-title { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; }
.subsection-title strong { font-size: 13px; }
.subsection-title span { color: var(--muted); font-size: 9px; }
.recent-draw-list { margin-top: 12px; border-top: 1px solid #eaedea; }
.draw-row { min-height: 49px; display: grid; grid-template-columns: 94px minmax(0, 1fr) 176px; align-items: center; gap: 12px; border-bottom: 1px solid #eaedea; }
.draw-row:last-child { border-bottom: 0; }
.draw-issue { font-size: 10px; font-weight: 800; }
.draw-numbers { min-width: 0; display: flex; flex-wrap: wrap; gap: 5px; }
.draw-number { width: 25px; height: 25px; display: grid; place-items: center; border-radius: 50%; background: var(--red); color: #fff; font-size: 9px; font-weight: 850; }
.draw-number.secondary { background: var(--blue); }
.draw-date { color: var(--muted); font-size: 9px; text-align: right; }
.history-empty { padding: 34px 22px; color: var(--muted); text-align: center; font-size: 12px; }
.history-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.history-item { min-width: 0; padding: 18px 22px; border-bottom: 1px solid #eaedea; }
.history-item:nth-child(odd) { border-right: 1px solid #eaedea; }
.history-item header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.history-item header strong, .history-item header span { display: block; }
.history-item header strong { font-size: 13px; }
.history-item header span { margin-top: 3px; color: var(--muted); font-size: 10px; }
.history-actions { display: flex; gap: 5px; }
.history-actions button { min-height: 30px; padding: 0 9px; border: 1px solid var(--line); border-radius: 5px; background: #fff; color: var(--ink); cursor: pointer; font-size: 10px; }
.history-actions button:last-child { color: #9a3e39; }
.history-item p { margin: 12px 0 0; overflow: hidden; color: var(--muted); font-size: 11px; line-height: 1.5; text-overflow: ellipsis; white-space: nowrap; }

.notice { margin-top: 18px; padding: 16px 18px; display: grid; grid-template-columns: auto 1fr; align-items: baseline; gap: 14px; border: 1px solid #dfd8c5; border-radius: 7px; background: #faf8f2; }
.notice strong { color: #805d20; font-size: 12px; }
.notice p { margin: 0; color: #756d5e; font-size: 11px; line-height: 1.65; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); padding: 10px 14px; transform: translate(-50%, 14px); border-radius: 6px; background: #1d2522; color: #fff; font-size: 12px; opacity: 0; pointer-events: none; transition: opacity 150ms ease, transform 150ms ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
footer { min-height: 74px; padding: 18px 24px calc(18px + env(safe-area-inset-bottom)); display: flex; align-items: center; justify-content: center; gap: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }

@media (max-width: 780px) {
  .topbar { min-height: 62px; padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .brand small { display: none; }
  .home-link { width: 38px; padding: 0; justify-content: center; }
  .home-link span:last-child { display: none; }
  main { width: calc(100% - 28px); padding: 34px 0 48px; }
  .intro { align-items: flex-start; flex-direction: column; gap: 10px; }
  h1 { font-size: 28px; }
  .workbench { grid-template-columns: 1fr; }
  .control-panel { padding: 20px 17px; }
  .result-panel { min-height: 360px; }
  .empty-state { min-height: 282px; }
  .ticket-list { padding: 7px 14px 16px; }
  .ticket-list li { padding: 10px 0; grid-template-columns: 25px minmax(0, 1fr); align-items: start; gap: 10px; }
  .ticket-groups { gap: 8px 14px; }
  .number-ball { width: 29px; height: 29px; font-size: 10px; }
  .entry-bets { grid-column: 2; text-align: left; }
  .history-list { grid-template-columns: 1fr; }
  .history-item:nth-child(odd) { border-right: 0; }
  .analysis-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { border-bottom: 1px solid #eaedea; }
  .metric:nth-child(3n) { border-right: 1px solid #eaedea; }
  .metric:nth-child(2n) { border-right: 0; }
  .metric:nth-child(-n+3) { border-bottom: 1px solid #eaedea; }
  .metric:nth-last-child(-n+2) { border-bottom: 0; }
  .frequency-panels { grid-template-columns: 1fr; }
  .frequency-panel:nth-child(odd) { border-right: 0; }
  .draw-row { grid-template-columns: 72px minmax(0, 1fr); padding: 8px 0; }
  .draw-date { grid-column: 2; text-align: left; }
  .notice { grid-template-columns: 1fr; gap: 5px; }
  footer { align-items: flex-start; flex-direction: column; gap: 4px; }
}

@media (display-mode: standalone) { .topbar { padding-top: env(safe-area-inset-top); } }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
