/* 우리술 계산기 — design system
   Forest + bone + burnt amber (시인성 우선, 모바일 퍼스트) */
:root {
  --bg: #eef1ed;
  --bg-soft: #f7f8f6;
  --surface: #ffffff;
  --surface-2: #f0f3f0;
  --ink: #152018;
  --ink-soft: #2a3830;
  --muted: #5a6a60;
  --line: #cfd8d2;
  --line-strong: #a8b8ae;
  --forest: #1f3d2e;
  --forest-mid: #2f5a44;
  --forest-soft: #dfece4;
  --accent: #c45c26;
  --accent-hover: #a64b1c;
  --accent-soft: #fdeee6;
  --ok: #176b42;
  --ok-bg: #e5f5ec;
  --warn: #9a5b00;
  --warn-bg: #fff4df;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --radius: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --shadow: 0 10px 30px rgba(21, 32, 24, 0.08);
  --shadow-sm: 0 2px 10px rgba(21, 32, 24, 0.06);
  --font: "Pretendard", "Noto Sans KR", "Apple SD Gothic Neo", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, monospace;
  --nav-h: 60px;
  --touch: 48px;
  --max: 720px;
  --max-wide: 960px;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    linear-gradient(180deg, rgba(238, 241, 237, 0.92), rgba(238, 241, 237, 0.97)),
    url("../img/texture.jpg");
  background-size: auto, 420px;
  background-attachment: fixed;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: var(--forest-mid);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  color: var(--accent);
}

/* Skip link */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--forest);
  color: #fff;
  padding: 0.75rem 1rem;
  z-index: 100;
}
.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
}

/* App shell */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0 1rem;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.02em;
  min-height: var(--touch);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--forest) 0%, var(--forest-mid) 100%);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 800;
  flex-shrink: 0;
}

.brand-text {
  font-size: 1rem;
}

.nav-toggle {
  width: var(--touch);
  height: var(--touch);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
}

.nav-toggle:focus-visible,
.nav a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(196, 92, 38, 0.45);
  outline-offset: 2px;
}

.nav {
  display: none;
  position: absolute;
  top: var(--nav-h);
  left: 0;
  right: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0.5rem;
  box-shadow: var(--shadow-sm);
  max-height: min(70dvh, 480px);
  overflow: auto;
}

.nav.is-open {
  display: block;
}

.nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.25rem;
}

.nav a {
  display: flex;
  align-items: center;
  min-height: var(--touch);
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
}

.nav a:hover,
.nav a[aria-current="page"] {
  background: var(--forest-soft);
  color: var(--forest);
}

@media (min-width: 900px) {
  .nav-toggle {
    display: none;
  }
  .nav {
    display: block;
    position: static;
    border: 0;
    box-shadow: none;
    padding: 0;
    max-height: none;
    overflow: visible;
    background: transparent;
  }
  .nav ul {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.15rem;
  }
  .nav a {
    min-height: 40px;
    padding: 0.4rem 0.7rem;
    font-size: 0.88rem;
  }
}

main {
  width: min(100% - 2rem, var(--max));
  margin: 0 auto;
  padding: 1.25rem 0 5rem;
}

main.wide {
  width: min(100% - 2rem, var(--max-wide));
}

/* Hero */
.page-hero {
  position: relative;
  overflow: hidden;
  border-radius: calc(var(--radius) + 4px);
  margin-bottom: 1.25rem;
  min-height: 160px;
  display: grid;
  align-items: end;
  background: var(--forest) center/cover no-repeat;
  color: #fff;
  box-shadow: var(--shadow);
}

.page-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, rgba(21, 32, 24, 0.88) 0%, rgba(21, 32, 24, 0.45) 55%, rgba(21, 32, 24, 0.25) 100%);
}

.page-hero > * {
  position: relative;
  z-index: 1;
  padding: 1.25rem 1.2rem 1.35rem;
}

.page-hero h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.35rem, 4.5vw, 1.85rem);
  line-height: 1.25;
  letter-spacing: -0.03em;
  font-weight: 800;
}

.page-hero p {
  margin: 0;
  max-width: 36ch;
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.95rem;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.15rem 1.1rem;
  margin-bottom: 1rem;
}

.card h2,
.section-title {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.hint,
.form-hint {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

/* Forms */
.form-stack {
  display: grid;
  gap: 1rem;
}

.field {
  display: grid;
  gap: 0.4rem;
}

.field label {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--ink-soft);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: center;
}

.unit {
  min-width: 2.5rem;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="search"],
select,
textarea {
  width: 100%;
  min-height: var(--touch);
  padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* iOS zoom prevent */
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--forest-mid);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(196, 92, 38, 0.18);
  outline: none;
}

input[readonly] {
  background: var(--surface-2);
  color: var(--ink-soft);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

input.is-invalid,
select.is-invalid {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.field-error {
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 1.2em;
}

/* Buttons */
.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-top: 0.25rem;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: var(--radius-sm);
  min-height: var(--touch);
  padding: 0.75rem 1rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  text-decoration: none;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 18px rgba(196, 92, 38, 0.28);
}

.btn-primary:hover {
  background: var(--accent-hover);
  color: #fff;
}

.btn-secondary {
  background: var(--surface);
  color: var(--ink-soft);
  border: 1.5px solid var(--line-strong);
}

.btn-secondary:hover {
  background: var(--surface-2);
}

.btn-ghost {
  background: transparent;
  color: var(--forest-mid);
  border: 1px solid transparent;
}

.btn-block {
  width: 100%;
}

/* Results */
.result-panel {
  display: none;
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius);
  border: 1.5px solid var(--forest-soft);
  background: linear-gradient(180deg, #fff 0%, var(--forest-soft) 160%);
}

.result-panel.is-visible {
  display: block;
  animation: rise 0.35s ease;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-value {
  font-size: clamp(1.8rem, 7vw, 2.4rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--forest);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.result-value small {
  font-size: 0.45em;
  color: var(--muted);
  font-weight: 700;
  margin-left: 0.2em;
}

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

.result-list li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid rgba(31, 61, 46, 0.1);
  font-size: 0.95rem;
}

.result-list li:last-child {
  border-bottom: 0;
}

.result-list .k {
  color: var(--muted);
}

.result-list .v {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* Alerts */
.alert {
  margin-top: 0.85rem;
  padding: 0.85rem 0.95rem;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  line-height: 1.5;
  border: 1px solid transparent;
}

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

.alert-warn {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: #f0d7a4;
}

.alert-ok {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: #b8e0c8;
}

.alert[hidden] {
  display: none !important;
}

/* Hub grid */
.hub-grid {
  display: grid;
  gap: 0.85rem;
}

@media (min-width: 640px) {
  .hub-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.hub-card {
  display: grid;
  gap: 0.45rem;
  padding: 1.1rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: inherit;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  min-height: 120px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.hub-card:hover {
  transform: translateY(-2px);
  border-color: var(--forest-mid);
  box-shadow: var(--shadow);
  color: inherit;
}

.hub-card .tag {
  display: inline-flex;
  width: fit-content;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--forest-soft);
  color: var(--forest);
  font-size: 0.75rem;
  font-weight: 700;
}

.hub-card h2 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.hub-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Chip / preset grid */
.chip-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

@media (min-width: 480px) {
  .chip-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.chip {
  min-height: 44px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--ink-soft);
  font: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  padding: 0.55rem 0.4rem;
}

.chip:hover {
  border-color: var(--forest-mid);
}

.chip.is-active {
  background: var(--forest);
  border-color: var(--forest);
  color: #fff;
}

/* Table (worisul) */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
  font-size: 0.92rem;
}

.table-wrap th,
.table-wrap td {
  padding: 0.7rem 0.65rem;
  border-bottom: 1px solid var(--line);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.table-wrap th {
  background: var(--forest);
  color: #fff;
  font-weight: 700;
  position: sticky;
  top: 0;
}

.table-wrap td:first-child,
.table-wrap th:first-child {
  text-align: left;
  font-weight: 700;
  background: var(--surface-2);
  position: sticky;
  left: 0;
  z-index: 1;
}

.table-wrap th:first-child {
  background: var(--forest-mid);
  z-index: 2;
}

.table-wrap tr:last-child td {
  border-bottom: 0;
}

.table-note {
  margin-top: 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Footer */
.app-footer {
  width: min(100% - 2rem, var(--max-wide));
  margin: 0 auto 1.5rem;
  padding: 1rem 0 2rem;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--line);
}

.app-footer a {
  color: var(--forest-mid);
}

/* Formula box */
.formula {
  margin: 0.75rem 0 0;
  padding: 0.85rem 0.95rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border-left: 4px solid var(--forest-mid);
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.formula code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: rgba(31, 61, 46, 0.08);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

/* Makesool field groups */
.fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 0.9rem 1.1rem;
  margin: 0 0 1rem;
  background: var(--surface);
}

.fieldset legend {
  padding: 0 0.4rem;
  font-weight: 800;
  color: var(--forest);
}

.req {
  color: var(--danger);
  font-weight: 800;
}

/* Utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.stack-sm { display: grid; gap: 0.5rem; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .result-panel.is-visible,
  .btn,
  .hub-card {
    animation: none !important;
    transition: none !important;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .app-header {
    background: #fff;
    backdrop-filter: none;
  }
}
