:root {
  color-scheme: light dark;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-sunken: #f0f1f4;
  --border: #dcdfe5;
  --text: #1c1f24;
  --text-muted: #666d78;
  --accent: #2f6fd0;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --danger-bg: #fdecea;

  /* 한국 로또 공 색상 */
  --ball-1: #fbc400;
  --ball-2: #69c8f2;
  --ball-3: #ff7272;
  --ball-4: #b4b4b4;
  --ball-5: #b0d840;
  --ball-text: #1c1f24; /* 다섯 색 모두 밝은 편이라 어두운 글자가 가장 잘 읽힌다 */

  --radius: 10px;
  --shadow: 0 1px 3px rgb(0 0 0 / 8%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --surface: #1e2128;
    --surface-sunken: #262a32;
    --border: #343943;
    --text: #e6e8ec;
    --text-muted: #9aa1ad;
    --accent: #5b9bf0;
    --accent-text: #10131a;
    --danger: #ff8a80;
    --danger-bg: #3a2320;
    --shadow: 0 1px 3px rgb(0 0 0 / 40%);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0 1rem 3rem;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

main,
.site-header,
.site-footer {
  max-width: 720px;
  margin: 0 auto;
}

/* ── 헤더 ─────────────────────────────────────────────── */

.site-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-start;
  justify-content: space-between;
  padding: 1.75rem 0 1.25rem;
}

.site-header h1 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.auth-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.auth-status strong {
  color: var(--text);
}

/* ── 패널 ─────────────────────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.panel h2 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}

.step {
  display: inline-grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.8rem;
  font-weight: 700;
}

.hint {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.optional {
  color: var(--text-muted);
  font-weight: 400;
}

/* ── 입력 행 ──────────────────────────────────────────── */

.rows {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.row__value {
  display: flex;
  flex: 1 1 16rem;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.row__value input {
  flex: 1 1 10rem;
  min-width: 0;
}

.row__actions {
  display: flex;
  gap: 0.25rem;
  margin-left: auto;
}

.row__type {
  flex: 0 0 auto;
}

.calendar-note {
  flex-basis: 100%;
  margin: 0;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.empty {
  margin: 0 0 0.75rem;
  padding: 1.25rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  text-align: center;
  font-size: 0.875rem;
}

/* ── 폼 컨트롤 ────────────────────────────────────────── */

input,
select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.55rem;
  max-width: 100%;
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}

.field label {
  font-size: 0.85rem;
  font-weight: 600;
}

.field small {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.generate-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.generate-bar .field {
  margin-bottom: 0;
}

.generate-bar .btn--primary {
  margin-left: auto;
}

/* ── 버튼 ─────────────────────────────────────────────── */

.btn {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0.45rem 0.9rem;
  background: transparent;
  color: var(--text);
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.btn--primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn--ghost {
  border-color: var(--border);
  background: var(--surface);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--surface-sunken);
}

.btn--link {
  color: var(--accent);
  padding-inline: 0;
  text-decoration: underline;
}

.btn--icon {
  border-color: var(--border);
  background: var(--surface);
  width: 2rem;
  height: 2rem;
  padding: 0;
  display: grid;
  place-items: center;
  line-height: 1;
}

.btn--icon:hover:not(:disabled) {
  background: var(--surface-sunken);
}

.btn--danger {
  color: var(--danger);
}

.btn--small {
  font-size: 0.8rem;
  padding: 0.3rem 0.6rem;
}

/* ── 결과 ─────────────────────────────────────────────── */

.game {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
  margin-bottom: 0.75rem;
  background: var(--surface-sunken);
}

.game__head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.game__name {
  font-weight: 700;
  font-size: 1rem;
  min-width: 1.25rem;
}

.game__actions {
  display: flex;
  gap: 0.35rem;
  margin-left: auto;
}

.balls {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
}

.ball {
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ball-text);
  background: var(--ball-4);
}

.ball--1 { background: var(--ball-1); }
.ball--2 { background: var(--ball-2); }
.ball--3 { background: var(--ball-3); }
.ball--4 { background: var(--ball-4); }
.ball--5 { background: var(--ball-5); }

.balls--compact .ball {
  width: 2rem;
  height: 2rem;
  font-size: 0.85rem;
}

.game__details {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border);
  font-size: 0.8rem;
}

.game__details dt {
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.game__details dd {
  margin: 0.2rem 0 0;
}

.game__details pre,
.game__details code {
  display: block;
  margin: 0;
  padding: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ── 이력 ─────────────────────────────────────────────── */

.entry {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
}

.entry:last-child {
  border-bottom: none;
}

.entry__meta {
  display: flex;
  flex-direction: column;
  min-width: 9rem;
}

.entry__label {
  font-weight: 600;
}

.entry__date {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.entry__actions {
  margin-left: auto;
}

/* ── 알림 ─────────────────────────────────────────────── */

.alert {
  margin: 0.75rem 0 0;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  font-size: 0.85rem;
}

.alert--error {
  background: var(--danger-bg);
  color: var(--danger);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  box-shadow: 0 4px 16px rgb(0 0 0 / 25%);
  z-index: 10;
}

/* ── 다이얼로그 ───────────────────────────────────────── */

.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(26rem, calc(100vw - 2rem));
}

.dialog::backdrop {
  background: rgb(0 0 0 / 45%);
}

.dialog__body {
  padding: 1.25rem;
}

.dialog__body h3 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}

.dialog__body input {
  width: 100%;
}

.dialog__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
}

.spacer {
  flex: 1 1 auto;
}

/* ── 푸터 ─────────────────────────────────────────────── */

.site-footer {
  padding: 0.5rem 0 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
}

@media (max-width: 480px) {
  .row__actions {
    margin-left: 0;
  }

  .generate-bar .btn--primary {
    margin-left: 0;
    flex: 1 1 100%;
  }
}

/* ── 시뮬레이션 ───────────────────────────────────────── */

.field__label {
  font-size: 0.85rem;
  font-weight: 600;
}

.number-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.number-input {
  width: 4rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  /* 숫자 입력의 증감 화살표는 좁은 칸에서 값을 가린다. */
  -moz-appearance: textfield;
  appearance: textfield;
}

.number-input::-webkit-outer-spin-button,
.number-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.sim-result {
  margin-top: 1rem;
}

.sim-heading {
  margin: 0.6rem 0 0.75rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.sim-best {
  margin: 0.75rem 0;
  padding: 0.6rem 0.75rem;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-weight: 600;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.5rem;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.7rem 0.8rem;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.tile__label {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.tile__value {
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

/* 이익과 손실은 색만으로 구분하지 않는다. 값 앞의 +/− 부호가 본래의 구분이다. */
.tile--gain .tile__value { color: #1f7a4d; }
.tile--loss .tile__value { color: var(--danger); }

@media (prefers-color-scheme: dark) {
  .tile--gain .tile__value { color: #5fd39a; }
}

/* ── 표 ───────────────────────────────────────────────── */

.prize-table {
  width: 100%;
  margin-top: 0.75rem;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.prize-table caption {
  margin-bottom: 0.4rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-align: left;
}

.prize-table th,
.prize-table td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.prize-table thead th,
.prize-table tbody th {
  text-align: left;
  font-weight: 600;
}

.prize-table thead th {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.prize-table thead th:not(:first-child) {
  text-align: right;
}

.prize-table .is-muted {
  color: var(--text-muted);
}

.prize-table input {
  width: 100%;
  max-width: 11rem;
  text-align: right;
}

/* ── 관리자 ───────────────────────────────────────────── */

.admin-block {
  padding-top: 1rem;
  margin-top: 1rem;
  border-top: 1px solid var(--border);
}

.admin-block:first-of-type {
  padding-top: 0;
  margin-top: 0;
  border-top: none;
}

.admin-block h3 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
}

.inline-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.inline-row label {
  font-size: 0.85rem;
  font-weight: 600;
}

.inline-row input[type='number'] {
  width: 7rem;
}

input[type='file'] {
  font: inherit;
  font-size: 0.85rem;
  max-width: 100%;
}

/* ── 알림 색상 ────────────────────────────────────────── */

.alert--ok {
  background: #e8f5ee;
  color: #1f7a4d;
}

.alert--warn {
  background: #fdf4e3;
  color: #8a5a00;
}

.alert--info {
  background: var(--surface-sunken);
  color: var(--text-muted);
}

@media (prefers-color-scheme: dark) {
  .alert--ok { background: #1d3328; color: #7fe0ae; }
  .alert--warn { background: #352c18; color: #e8c579; }
}
