:root {
  color-scheme: light dark;
  --ink: #1c1a16;
  --muted: #5c5448;
  --paper: #faf7f0;
  --card: #ffffff;
  --line: #e0d8cc;
  --stroke: #3d3020;
  --accent: #2d6a4f;
  --accent-light: #40916c;
  --accent-ink: #f0fff8;
  --warn-bg: #fff8e1;
  --warn-border: #f0c040;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell, 'Noto Sans', sans-serif;
  --radius: 10px;
  --shadow: 0 4px 20px rgba(28, 24, 16, 0.08);
  --sidebar-w: 270px;
  --header-h: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f0ead8;
    --muted: #a89c88;
    --paper: #181510;
    --card: #201c16;
    --line: #38322a;
    --stroke: #d0c0a8;
    --accent: #52b788;
    --accent-light: #74c69d;
    --accent-ink: #0a1a10;
    --warn-bg: #2a2010;
    --warn-border: #806010;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  }
}

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

html, body {
  margin: 0;
  height: 100%;
}

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

body {
  font-family: var(--font);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

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

/* ─── Header ─── */
.app-header {
  flex-shrink: 0;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 0.5rem 1rem;
  height: var(--header-h);
}

.app-header__inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 100%;
}

.app-header__title-row {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand-link {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  opacity: 0.85;
  transition: opacity 0.15s;
}

.brand-link:hover { opacity: 1; }

.brand-logo {
  display: block;
  border-radius: 6px;
}

.app-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-sub {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.app-link {
  font-size: 0.82rem;
  font-weight: 550;
  white-space: nowrap;
}

/* ─── Layout ─── */
.app-body {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  overflow-y: auto;
  padding: 0.85rem;
  border-right: 1px solid var(--line);
  background: var(--card);
  display: flex;
  flex-direction: column;
  gap: 0;
}

.main-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* ─── 3D canvas ─── */
.shanty-3d-root {
  flex: 1;
  min-height: 0;
  touch-action: none;
  overflow: hidden;
  background: #d4e8f0;
}

.shanty-3d-root canvas {
  display: block;
}

/* ─── Output section ─── */
.output-section {
  flex-shrink: 0;
  height: min(38vh, 300px);
  display: flex;
  flex-direction: column;
  border-top: 2px solid var(--line);
  background: var(--card);
}

.tab-bar {
  display: flex;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 0.5rem 1rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  min-height: 36px;
}

.tab-btn[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panels {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-panel {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 0.75rem 1rem;
}

/* ─── Forms ─── */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-bottom: 0.65rem;
}

.field-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field input[type='number'],
.field select {
  width: 100%;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0.35rem 0.55rem;
  font: inherit;
  font-size: 0.9rem;
  background: var(--paper);
  color: var(--ink);
}

.field input[type='number']:focus,
.field select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field--inline {
  flex-direction: row;
  align-items: center;
  margin-top: 0.25rem;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
}

.toggle-label input[type='checkbox'] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0.2rem 0 0;
  line-height: 1.4;
}

/* ─── Summary box ─── */
.summary-box {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.summary-box p {
  margin: 0 0 0.2rem;
  font-size: 0.78rem;
  color: var(--muted);
}

/* ─── Buttons ─── */
.btn {
  border: none;
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
  white-space: nowrap;
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
}

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

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

/* ─── Output tables ─── */
.output-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.output-table th {
  text-align: left;
  padding: 0.3rem 0.5rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.output-table td {
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.output-table td:nth-child(2) {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--accent-light);
  white-space: nowrap;
}

.output-table .total-row td {
  border-top: 2px solid var(--line);
  border-bottom: none;
  padding-top: 0.5rem;
}

.output-table .note-cell {
  color: var(--muted);
  font-size: 0.75rem;
}

/* ─── Cost total ─── */
.cost-total {
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: color-mix(in srgb, var(--accent) 8%, var(--paper));
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--line));
}

.cost-total p { margin: 0; font-size: 0.82rem; }

.cost-total .total-figure {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent-light);
}

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

/* ─── Build guide ─── */
.callout {
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.75rem;
  font-size: 0.82rem;
  line-height: 1.5;
}

.callout--warning {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
}

.callout--warning ul {
  margin: 0;
  padding-left: 1.2em;
}

.callout--warning li { margin-bottom: 0.25rem; }

.guide-steps {
  margin: 0;
  padding-left: 1.4em;
  font-size: 0.82rem;
}

.guide-steps li {
  margin-bottom: 0.65rem;
  line-height: 1.5;
}

.guide-steps li strong {
  display: block;
  margin-bottom: 0.15rem;
  font-size: 0.85rem;
}

/* ─── Share toast ─── */
.share-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--stroke);
  color: var(--paper);
  padding: 0.5rem 1.25rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 100;
}

.share-toast.visible { opacity: 1; }

/* ─── Mobile ─── */
@media (max-width: 640px) {
  body { overflow: auto; height: auto; }

  .app-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    overflow: visible;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: none;
  }

  .shanty-3d-root {
    height: min(60vw, 320px);
    flex: none;
  }

  .output-section {
    height: auto;
    max-height: 50vh;
    overflow: hidden;
  }

  .app-sub { display: none; }

  .header-actions .app-link { display: none; }
}

/* ─── Print ─── */
@media print {
  body { overflow: visible; height: auto; display: block; }
  .app-header { position: static; backdrop-filter: none; }
  .header-actions { display: none; }
  .app-body { display: block; overflow: visible; }
  .sidebar { display: none; }
  .main-col { display: block; }
  .shanty-3d-root { display: none; }
  .output-section { height: auto; max-height: none; border: none; }
  .tab-bar { display: none; }
  .tab-panels { position: static; }
  .tab-panel { display: block !important; position: static; overflow: visible; }
  .tab-panel + .tab-panel { border-top: 1px solid #ccc; padding-top: 1rem; margin-top: 1rem; }
}
