:root {
  --ink: #172027;
  --muted: #667781;
  --line: #d9e2e7;
  --paper: #f5f8f7;
  --panel: #ffffff;
  --dark: #101820;
  --green: #0d7b5f;
  --gold: #f2b743;
  --red: #d85b52;
  --blue: #3b70c2;
  --shadow: 0 18px 48px rgba(24, 33, 40, .11);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(13, 123, 95, .08), transparent 38%),
    radial-gradient(circle at 92% 4%, rgba(242, 183, 67, .16), transparent 24%),
    var(--paper);
}

button, input { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }

.locked .shell {
  display: none;
}

body:not(.locked) .pin-gate {
  display: none;
}

.pin-gate {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(22px, env(safe-area-inset-top)) 22px max(22px, env(safe-area-inset-bottom));
}

.pin-card {
  width: min(100%, 430px);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.pin-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border-radius: 10px;
  color: #111a20;
  background: var(--gold);
  font-weight: 950;
  box-shadow: 0 12px 28px rgba(24, 33, 40, .15);
}

.pin-card h1 {
  margin-top: 6px;
  font-size: 28px;
  line-height: 1.2;
}

.pin-card > p:not(.eyebrow):not(.pin-error):not(.pin-notice) {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.pin-notice {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.pin-form {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.pin-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.pin-form input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 13px;
  color: var(--ink);
  background: #fff;
  font-size: 22px;
  font-weight: 850;
  letter-spacing: 0;
}

.pin-error {
  min-height: 20px;
  margin-top: 12px;
  color: var(--red);
  font-size: 13px;
  line-height: 1.45;
}

.pin-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
}

.pin-link {
  min-height: 34px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 850;
  text-align: left;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
}

.rail {
  min-height: 100vh;
  padding: 26px 20px;
  color: #f7fbfa;
  background: var(--dark);
  position: sticky;
  top: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: #111a20;
  background: var(--gold);
  font-weight: 900;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .26);
}

.brand strong {
  display: block;
  font-size: 20px;
}

.brand span:last-child {
  display: block;
  margin-top: 3px;
  color: #aebdc1;
  font-size: 12px;
  line-height: 1.4;
}

.rail-stat {
  padding: 18px 0;
  border-top: 1px solid rgba(255, 255, 255, .14);
}

.rail-stat span {
  display: block;
  color: #b9c6ca;
  font-size: 12px;
}

.rail-stat strong {
  display: block;
  margin-top: 6px;
  font-size: 26px;
}

.rail-actions {
  display: grid;
  gap: 9px;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, .14);
}

.primary,
.secondary,
.text-button {
  min-height: 42px;
  border-radius: 8px;
  font-weight: 850;
}

.primary {
  border: 0;
  color: #111a20;
  background: var(--gold);
  box-shadow: 0 10px 24px rgba(242, 183, 67, .2);
}

.primary.dark {
  color: #fff;
  background: var(--green);
  box-shadow: 0 10px 24px rgba(13, 123, 95, .17);
}

.secondary {
  border: 1px solid rgba(255, 255, 255, .18);
  color: #f7fbfa;
  background: transparent;
}

.text-button {
  min-width: 78px;
  padding: 0 12px;
  border: 1px solid rgba(13, 123, 95, .28);
  color: var(--green);
  background: #fff;
}

.file-button {
  display: grid;
  place-items: center;
}

.file-button input,
.hidden {
  display: none;
}

.log {
  display: grid;
  gap: 7px;
  margin-top: 14px;
  color: #c0ced1;
  font-size: 12px;
  line-height: 1.55;
}

.log-line {
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .07);
  white-space: pre-wrap;
}

.main {
  min-width: 0;
  padding: 30px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  color: var(--green);
  font-size: 13px;
  font-weight: 900;
}

h1 {
  margin-top: 6px;
  font-size: 32px;
  line-height: 1.18;
  letter-spacing: 0;
}

.status-pill,
.mini-badge {
  min-height: 31px;
  display: inline-flex;
  align-items: center;
  padding: 0 11px;
  border-radius: 999px;
  color: var(--green);
  background: #dff1ec;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.control-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: 14px;
  align-items: stretch;
  margin-bottom: 18px;
}

.control-band > div,
.bonus-box {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 25px rgba(24, 33, 40, .05);
}

.control-band h2 {
  margin-bottom: 10px;
  font-size: 15px;
}

.methods {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 9px;
}

.method {
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
}

.method.active {
  border-color: var(--green);
  box-shadow: inset 0 0 0 2px rgba(13, 123, 95, .15);
}

.method strong {
  display: block;
  margin-bottom: 5px;
  font-size: 13px;
}

.method span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.bonus-box {
  display: grid;
  align-content: space-between;
  gap: 12px;
}

.bonus-box strong {
  font-size: 14px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.segment {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  font-size: 13px;
  font-weight: 850;
}

.segment.active {
  border-color: var(--green);
  color: var(--green);
  background: #dff1ec;
}

.dashboard-grid,
.lower-grid {
  display: grid;
  grid-template-columns: minmax(350px, .9fr) minmax(0, 1.1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  font-size: 18px;
}

.panel-head p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.candidate-list,
.game-list,
.optimized-layout,
.draw-form,
.backtest-status {
  padding: 16px;
}

.candidate-list {
  display: grid;
  gap: 9px;
}

.candidate {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) minmax(60px, max-content);
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid #edf2f4;
  border-radius: 8px;
}

.candidate strong {
  font-size: 13px;
}

.candidate span {
  color: var(--muted);
  font-size: 12px;
}

.score {
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
}

.ball,
.small-ball {
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 900;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .13);
}

.ball {
  width: 38px;
  height: 38px;
  font-size: 14px;
}

.small-ball {
  width: 30px;
  height: 30px;
  font-size: 12px;
}

.b1 { color: #172027; background: #f2c14e; }
.b2 { background: #4f86d7; }
.b3 { background: #d95d54; }
.b4 { background: #707e87; }
.b5 { background: #45a978; }

.game-list {
  display: grid;
  gap: 10px;
}

.game {
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 1px solid #edf2f4;
  border-radius: 8px;
  background: #fff;
}

.game-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.ball-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.game .ball-row {
  gap: 7px;
}

.game-reason {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.optimized-panel,
.lower-grid {
  margin-top: 18px;
}

.optimized-layout {
  display: grid;
  grid-template-columns: minmax(320px, .82fr) minmax(0, 1.18fr);
  gap: 18px;
}

.optimized-layout h3 {
  margin-bottom: 10px;
  font-size: 14px;
}

.game-list.compact {
  padding: 14px 0 0;
}

.formula-list {
  display: grid;
  gap: 8px;
}

.formula {
  display: grid;
  grid-template-columns: minmax(128px, .75fr) minmax(0, 1.25fr);
  gap: 10px;
  padding: 10px;
  border: 1px solid #edf2f4;
  border-radius: 8px;
}

.formula strong {
  display: block;
  font-size: 13px;
  margin-bottom: 4px;
}

.formula p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.draw-form {
  display: grid;
  gap: 12px;
}

.draw-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.draw-form input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  color: var(--ink);
  background: #fff;
  font-size: 16px;
}

.number-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.backtest-status {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.table-wrap {
  overflow-x: auto;
  padding: 0 16px 16px;
}

.backtest-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.backtest-table th,
.backtest-table td {
  padding: 10px 8px;
  border-bottom: 1px solid #edf2f4;
  text-align: right;
  white-space: nowrap;
}

.backtest-table th:first-child,
.backtest-table td:first-child {
  text-align: left;
}

@media (max-width: 1120px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .rail {
    min-height: 0;
    position: static;
    display: grid;
    grid-template-columns: minmax(170px, 1fr) repeat(2, minmax(110px, max-content));
    gap: 14px;
    align-items: start;
  }

  .rail-actions,
  .log {
    grid-column: 1 / -1;
  }

  .methods {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .control-band,
  .dashboard-grid,
  .lower-grid,
  .optimized-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .pin-gate {
    align-items: start;
    padding: max(18px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
  }

  .pin-card {
    padding: 22px;
  }

  .main {
    padding: 18px 14px 28px;
  }

  .rail {
    padding: 18px 14px;
    grid-template-columns: 1fr 1fr;
  }

  .brand {
    grid-column: 1 / -1;
    margin-bottom: 2px;
  }

  .topbar,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  h1 {
    font-size: 25px;
  }

  .methods {
    grid-template-columns: 1fr;
  }

  .number-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .candidate {
    grid-template-columns: 38px minmax(0, 1fr);
  }

  .candidate .score {
    grid-column: 2;
  }
}
