:root {
  --bg: #0f1419;
  --bg-elevated: #171d25;
  --panel: #1c2430;
  --border: #2a3544;
  --text: #e8eef6;
  --muted: #93a1b3;
  --accent: #6ec8ff;
  --accent-strong: #3aa8ef;
  --good: #4fd1a5;
  --warn: #f0b35a;
  --unit-eok: #ffd54a;
  --unit-man: #f0a06a;
  --danger: #f07178;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --font: "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(110, 200, 255, 0.16), transparent 55%),
    radial-gradient(900px 500px at 90% 0%, rgba(79, 209, 165, 0.12), transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  line-height: 1.5;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}

.brand {
  display: flex;
  gap: 0.9rem;
  align-items: center;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  object-fit: cover;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.header-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(28, 36, 48, 0.85);
  color: var(--muted);
  font-size: 0.85rem;
}

.chip select,
input,
button,
.file-btn {
  font: inherit;
}

.chip select {
  border: 0;
  background: transparent;
  color: var(--text);
  outline: none;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.layout > * {
  min-width: 0;
}

.panel {
  background: color-mix(in srgb, var(--panel) 92%, black);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.2rem 1.35rem;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.panel-head h2,
.fieldset legend {
  margin: 0;
  font-size: 1.05rem;
}

.legend-check {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.28rem 0.75rem 0.28rem 0.5rem;
  border: 1px solid #d4a017;
  border-radius: 999px;
  background: rgba(255, 213, 74, 0.16);
  color: #ffd54a;
  font-weight: 700;
  cursor: pointer;
}

.legend-check input {
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  accent-color: #ffd54a;
}

#schdSettings[hidden],
.summary-schd[hidden] {
  display: none !important;
}

#yearTable:not(.schd-on) .col-schd,
#yearTable:not(.schd-on) .col-dividend {
  display: none;
}

.field {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
}

.field[hidden],
.withdrawal-field[hidden] {
  display: none !important;
}

.field label {
  color: var(--muted);
  font-size: 0.88rem;
}

.stepper {
  display: grid;
  grid-template-columns: 2.6rem minmax(0, 1fr) 2.6rem;
  gap: 0.4rem;
  align-items: stretch;
}

.step-btn {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  touch-action: manipulation;
}

.step-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.step-btn:active {
  transform: translateY(1px);
}

.input-with-suffix {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-elevated);
}

.input-with-suffix:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(110, 200, 255, 0.15);
}

.input-with-suffix input,
.field > input[type="text"],
.field > input[type="number"] {
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0.7rem 0.85rem;
  outline: none;
  font-variant-numeric: tabular-nums;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  appearance: none;
  margin: 0;
}

.field > input[type="text"],
.field > input[type="number"] {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elevated);
}

.field > input[type="text"]:focus,
.field > input[type="number"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(110, 200, 255, 0.15);
}

.suffix {
  display: grid;
  place-items: center;
  min-width: 2.6rem;
  padding: 0 0.7rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  border-left: 1px solid var(--border);
  font-size: 0.9rem;
}

.fieldset {
  margin: 1.1rem 0 0;
  padding: 0.9rem 0 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.radio-row {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 0.85rem;
}

.radio-row label {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  color: var(--text);
  font-size: 0.92rem;
  cursor: pointer;
}

.hint {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.btn,
.file-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 10px;
  padding: 0.55rem 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.btn:hover,
.file-btn:hover {
  border-color: var(--accent);
}

.btn:active,
.file-btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: linear-gradient(160deg, var(--accent), var(--accent-strong));
  border-color: transparent;
  color: #061018;
  font-weight: 650;
}

.btn.ghost {
  background: transparent;
}

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

.scenario-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.scenario-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(15, 20, 25, 0.45);
}

.scenario-list .name {
  font-size: 0.9rem;
  word-break: break-word;
}

.scenario-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.1rem;
}

.stat {
  padding: 0.85rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(15, 20, 25, 0.4);
}

.stat h3 {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 550;
}

.stat-value {
  margin: 0.35rem 0 0;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  letter-spacing: -0.02em;
  word-break: break-word;
}

.stat-final {
  background: rgba(126, 74, 176, 0.38);
  border-color: #c9a0e8;
}

.stat-final .stat-value {
  color: #e7c6ff;
  font-size: 1.35rem;
}

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

.stat-schd {
  background: rgba(255, 213, 74, 0.14);
  border-color: #d4a017;
}

.stat-schd .stat-value {
  color: #ffd54a;
  font-size: 1.35rem;
}

.stat-value.positive {
  color: var(--good);
}

.stat-value.negative {
  color: var(--danger);
}

.chart-wrap {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(15, 20, 25, 0.35);
  padding: 0.75rem;
  margin-bottom: 1rem;
}

.chart-wrap canvas {
  width: 100%;
  height: auto;
  display: block;
  cursor: crosshair;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.unit-eok {
  color: var(--unit-eok);
}

.unit-man {
  color: var(--unit-man);
}

td.num-up {
  color: var(--good);
}

td.num-down {
  color: var(--danger);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}

th, td {
  padding: 0.65rem 0.75rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--panel);
}

thead th {
  position: sticky;
  top: 0;
  background: #222b38;
  color: var(--muted);
  font-weight: 600;
  z-index: 1;
}

thead th:first-child {
  z-index: 2;
}

tbody tr:hover td {
  background: rgba(110, 200, 255, 0.06);
}

tbody tr:hover td:first-child {
  background: #243041;
}

th.col-end,
td.col-end {
  background: rgba(126, 74, 176, 0.34);
}

thead th.col-end {
  background: #3a2a4d;
}

tbody tr:hover td.col-end {
  background: rgba(126, 74, 176, 0.5);
}

th.col-schd,
td.col-schd {
  background: rgba(255, 213, 74, 0.12);
}

thead th.col-schd {
  background: #3d3420;
}

tbody tr:hover td.col-schd {
  background: rgba(255, 213, 74, 0.22);
}

.examples {
  margin-bottom: 1rem;
}

.examples-label {
  margin: 0 0 0.45rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.example-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.example-btn.active {
  border-color: var(--accent);
  background: rgba(110, 200, 255, 0.12);
}

.social {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0.35rem 0;
}

.social a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
}

.social img {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  display: block;
}

.social a:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.footer {
  margin-top: 1.75rem;
  color: var(--muted);
  font-size: 0.85rem;
  display: grid;
  gap: 0.35rem;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

.seo-note {
  margin-top: 1.75rem;
  padding: 1.15rem 1.2rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 92%, black);
}

.seo-note h2 {
  margin: 1.1rem 0 0.45rem;
  font-size: 1.05rem;
}

.seo-note h2:first-child {
  margin-top: 0;
}

.seo-note p,
.guide p {
  margin: 0.4rem 0 0;
  color: var(--muted);
}

.guide-links {
  list-style: none;
  margin: 0.7rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.guide-links a {
  display: block;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(15, 20, 25, 0.4);
  color: var(--text);
  text-decoration: none;
}

.guide-links a:hover {
  border-color: var(--accent);
}

.guide {
  max-width: 760px;
}

.guide h1 {
  margin: 0.4rem 0 0.6rem;
  font-size: 1.7rem;
  letter-spacing: -0.03em;
  line-height: 1.3;
}

.guide > p a {
  color: var(--accent);
}

.guide .summary h2 {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 550;
}

.guide-actions .btn {
  color: var(--text);
}

.guide-actions .btn.primary {
  color: #061018;
}

.guide .lead {
  color: var(--text);
  font-size: 1.05rem;
}

.guide .summary {
  margin-top: 1rem;
}

.guide-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0 0.4rem;
}

.guide-actions a {
  text-decoration: none;
}

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

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

@media (max-width: 520px) {
  .app {
    padding: 0.85rem 0.75rem 2.25rem;
  }

  .header {
    flex-direction: column;
    gap: 0.75rem;
  }

  .brand {
    align-items: flex-start;
  }

  .brand-mark {
    width: 2.4rem;
    height: 2.4rem;
    border-radius: 12px;
  }

  .brand h1 {
    font-size: 1.28rem;
    line-height: 1.25;
  }

  .tagline {
    font-size: 0.85rem;
  }

  .header-controls {
    width: 100%;
  }

  .panel {
    padding: 0.95rem 0.8rem 1.1rem;
  }

  .example-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .example-btn {
    width: 100%;
    text-align: center;
  }

  .summary {
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem;
  }

  .stat {
    padding: 0.7rem 0.7rem;
  }

  .stat-value,
  .stat-final .stat-value {
    font-size: 1.02rem;
  }

  .chart-wrap {
    padding: 0.4rem 0.25rem 0.2rem;
  }

  .input-with-suffix input,
  .field > input[type="text"],
  .chip select,
  .btn,
  .file-btn {
    font-size: 16px;
  }

  .stepper {
    grid-template-columns: 2.75rem minmax(0, 1fr) 2.75rem;
  }

  .step-btn {
    min-height: 2.75rem;
  }

  .btn-row .btn,
  .btn-row .file-btn {
    flex: 1 1 calc(50% - 0.5rem);
    text-align: center;
  }

  th,
  td {
    padding: 0.5rem 0.4rem;
    font-size: 0.78rem;
  }

  #yearTable th:nth-child(2),
  #yearTable td:nth-child(2) {
    display: none;
  }

  .social a {
    flex: 1 1 auto;
    justify-content: center;
  }
}
