:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #10151c;
  --ink-soft: #55606d;
  --line: #dfe3e8;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --field: #ffffff;
  --field-line: #c8cfd7;
  --good: #15803d;
  --good-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --shadow: 0 1px 2px rgba(16, 21, 28, .06), 0 4px 16px rgba(16, 21, 28, .05);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --card: #161b22;
    --ink: #e7edf3;
    --ink-soft: #9aa7b4;
    --line: #263040;
    --brand: #2dd4bf;
    --brand-ink: #052e2b;
    --field: #0d1117;
    --field-line: #313c4d;
    --good: #4ade80;
    --good-bg: #0c2f1c;
    --warn: #fbbf24;
    --warn-bg: #362a08;
    --bad: #f87171;
    --bad-bg: #3a1414;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 18px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.app__header { text-align: center; margin: 8px 0 20px; }
.app__header h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -.01em; }
.app__sub { margin: 0; color: var(--ink-soft); font-size: .95rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 1.05rem; margin: 0 0 4px; }

.hint { color: var(--ink-soft); font-size: .85rem; margin: 0 0 12px; }
.hint code {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: .82em;
}

/* Winding rows */
.rows { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.row {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  align-items: center;
  gap: 8px;
}
.row .times { color: var(--ink-soft); font-weight: 600; }
.row .field-wrap { display: flex; flex-direction: column; }
.row .field-wrap small { font-size: .7rem; color: var(--ink-soft); margin-top: 2px; }

input, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--field-line);
  border-radius: 10px;
  padding: 11px 12px;
  width: 100%;
  min-height: 44px;
}
input:focus, textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
  border-color: var(--brand);
}
input[type="number"] { -moz-appearance: textfield; }

.spools { resize: vertical; min-height: 56px; }

.maxrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  font-size: .9rem;
  color: var(--ink-soft);
}
.maxrow input { max-width: 90px; text-align: center; }

/* Buttons */
.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn--ghost {
  background: transparent;
  border-color: var(--field-line);
  color: var(--brand);
}
.btn--ghost:hover { background: var(--bg); }
.btn--icon {
  background: transparent;
  border: 1px solid var(--field-line);
  color: var(--ink-soft);
  width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 1.2rem;
  line-height: 1;
}
.btn--icon:hover { color: var(--bad); border-color: var(--bad); }
.btn--icon:disabled { opacity: .35; cursor: not-allowed; }

/* Target */
.target {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 10px 0 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}
.target__label { font-size: .8rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; }
.target__value { font-size: 2.2rem; font-weight: 700; color: var(--brand); line-height: 1.1; }
.target__detail { font-size: .85rem; color: var(--ink-soft); }

/* Message */
.message {
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: .9rem;
}

/* Results table */
.tablewrap { overflow-x: auto; }
.combos { width: 100%; border-collapse: collapse; font-size: .92rem; }
.combos th, .combos td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.combos th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
.combos .num { text-align: right; }
.combos tbody tr:first-child { background: color-mix(in srgb, var(--brand) 8%, transparent); }
.combos .combo-dias { font-weight: 600; }

.badge {
  display: inline-block;
  font-size: .68rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--good-bg);
  color: var(--good);
  margin-left: 6px;
  vertical-align: middle;
}

.dev { font-weight: 700; }
.dev--good { color: var(--good); }
.dev--warn { color: var(--warn); }
.dev--bad  { color: var(--bad); }

.app__footer {
  text-align: center;
  color: var(--ink-soft);
  font-size: .78rem;
  margin-top: 8px;
}

@media (max-width: 420px) {
  .target__value { font-size: 1.9rem; }
  .row { grid-template-columns: 1fr auto 1fr auto; }
}
