:root {
  --bg: #DCD8CE;
  --surface: #EAE6DC;
  --surface-alt: #D4CFC4;
  --text: #1A1A20;
  --text-muted: #5A5A66;
  --border: rgba(26, 26, 32, 0.14);
  --primary: #FF5E1A;
  --primary-dark: #D9480F;
  --primary-soft: rgba(255, 199, 0, 0.22);
  --success: #059669;
  --success-soft: #ecfdf5;
  --danger: #dc2626;
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow-card: 0 6px 20px rgba(24, 22, 16, 0.08);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 85% 360px at 50% 0%, rgba(255, 199, 0, 0.1), transparent 70%),
    radial-gradient(rgba(26, 26, 32, 0.08) 1px, transparent 1px);
  background-size: 100% 100%, 22px 22px;
  background-repeat: no-repeat, repeat;
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.app-shell {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--bg);
  padding-bottom: 44px;
}

/* Minimal Header */
.top-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-link {
  text-decoration: none;
}

.brand-badge {
  background: var(--text);
  color: #fff;
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-divider {
  color: #cbd5e1;
  font-size: 14px;
}

.brand-title {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-pill-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
}

.icon-pill-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: #bfdbfe;
}

.text-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.text-btn:hover {
  background: var(--surface-alt);
  color: var(--text);
}

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

/* Main */
.main-content {
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 2px;
}

.breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
}

.breadcrumb a:hover {
  color: var(--primary);
}

/* Mode Tabs */
.mode-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  background: var(--surface);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
}

.mode-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 4px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.mode-tab:hover {
  color: var(--text);
}

.mode-tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.22);
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow-card);
}

.calc-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Display Screen */
.display-screen {
  background: #0f172a;
  color: #f8fafc;
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.display-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 20px;
}

.last-formula {
  font-size: 12px;
  color: #94a3b8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mem-mini-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.mem-badge {
  font-size: 10px;
  font-weight: 700;
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.2);
  padding: 2px 6px;
  border-radius: 4px;
}

.mem-mini-btn {
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(255, 255, 255, 0.06);
  color: #cbd5e1;
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 5px;
  cursor: pointer;
}

.mem-mini-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.expression-line {
  font-size: 20px;
  font-weight: 600;
  color: #cbd5e1;
  text-align: right;
  word-break: break-all;
  line-height: 1.3;
  min-height: 26px;
}

.result-copy-area {
  width: 100%;
  border: none;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  padding: 6px 8px;
  margin-top: 2px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: background-color 0.15s, transform 0.08s;
}

.result-copy-area:hover {
  background: rgba(255, 255, 255, 0.09);
}

.result-copy-area:active {
  transform: scale(0.99);
}

.korean-unit {
  font-size: 12px;
  font-weight: 600;
  color: #60a5fa;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-right-wrap {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-left: auto;
}

.copy-hint-badge {
  font-size: 10px;
  font-weight: 600;
  color: #94a3b8;
  opacity: 0;
  transition: opacity 0.15s;
  white-space: nowrap;
}

.result-copy-area:hover .copy-hint-badge,
.copy-hint-badge.copied {
  opacity: 1;
}

.copy-hint-badge.copied {
  color: #34d399;
}

.live-result {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

.live-result.is-error {
  font-size: 18px;
  color: #fca5a5;
}

/* Slim Utility Strip */
.quick-tax-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.quick-chip {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  padding: 6px 2px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}

.quick-chip:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

/* Ergonomic 4x5 Keypad */
.keypad-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.key-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 21px;
  font-weight: 700;
  height: 56px;
  border-radius: 13px;
  cursor: pointer;
  transition: transform 0.08s cubic-bezier(0.2, 0, 0, 1), background-color 0.1s, box-shadow 0.1s;
  box-shadow: 0 2px 0 rgba(15, 23, 42, 0.05);
  user-select: none;
}

.key-btn:hover {
  background: var(--surface-alt);
}

.key-btn:active,
.key-btn.kbd-active {
  transform: scale(0.94);
  background: #e2e8f0;
  box-shadow: none;
}

.key-fn {
  background: #f1f5f9;
  color: #334155;
  font-size: 17px;
}

.key-sub {
  font-size: 17px;
  color: var(--text-muted);
}

.key-op {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: #dbeafe;
  font-size: 23px;
}

.key-op:hover {
  background: #dbeafe;
}

.key-eq {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary-dark);
  font-size: 25px;
  box-shadow: 0 3px 10px rgba(37, 99, 235, 0.28);
}

.key-eq:hover {
  background: var(--primary-dark);
}

.key-eq:active,
.key-eq.kbd-active {
  background: #1e40af;
  transform: scale(0.94);
}

.kbd-tip-line {
  margin-top: 10px;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
}

.kbd-tip-line code {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 10px;
}

/* Sub-calculators */
.tool-subcard {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.subcard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.subcard-title {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
}

.subcard-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 3px 8px;
  border-radius: 999px;
}

.inline-calc-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.num-input {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  padding: 9px 11px;
  border-radius: 10px;
  width: 120px;
  flex: 1;
  min-width: 85px;
  font-variant-numeric: tabular-nums;
}

.num-input.small {
  max-width: 78px;
  flex: 0 0 78px;
}

.num-input.full {
  width: 100%;
}

.num-input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.inline-txt {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
}

.dir-select {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 9px 8px;
  border-radius: 10px;
  color: var(--text);
}

.subcard-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.result-accent {
  color: var(--primary);
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.mini-copy-btn {
  border: 1px solid #bfdbfe;
  background: #fff;
  color: var(--primary);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 6px;
  cursor: pointer;
}

.dual-result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.dual-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.dual-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

.dual-box strong {
  font-size: 17px;
  font-weight: 800;
}

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

.unit-cat-row {
  grid-template-columns: repeat(4, 1fr);
}

.seg-btn {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 6px;
  border-radius: 9px;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
}

.tax-input-wrap {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.input-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}

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

.preset-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.preset-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.tax-summary-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tax-line {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: var(--text-muted);
}

.tax-line strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.tax-line.total {
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  font-weight: 700;
  color: var(--text);
}

.secondary-btn {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
}

.secondary-btn:hover {
  background: #e2e8f0;
}

.full-btn {
  width: 100%;
}

/* Unit Converter */
.unit-converter-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: end;
}

.unit-box {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.unit-arrow {
  font-size: 18px;
  font-weight: 800;
  color: var(--primary);
  padding-bottom: 10px;
}

.unit-quick-ref {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--primary-soft);
  padding: 9px 11px;
  border-radius: 9px;
}

/* History Memo Tape */
.history-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.history-title {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
}

.history-sub {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--text-muted);
}

.history-head-actions {
  display: flex;
  gap: 6px;
}

.selected-sum-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--primary-soft);
  border: 1px solid #bfdbfe;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}

.history-empty {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  padding: 14px 8px;
  background: var(--surface-alt);
  border-radius: 10px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.history-check {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.history-body {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.history-expr {
  font-size: 11px;
  color: var(--text-muted);
  word-break: break-all;
}

.history-res {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.history-memo-input {
  width: 94px;
  border: 1px dashed #cbd5e1;
  background: #fff;
  border-radius: 6px;
  padding: 4px 7px;
  font-family: inherit;
  font-size: 11px;
  color: var(--text);
}

.history-memo-input:focus {
  outline: none;
  border-style: solid;
  border-color: var(--primary);
}

.history-del-btn {
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 14px;
  line-height: 1;
  padding: 4px;
  cursor: pointer;
  border-radius: 6px;
}

.history-del-btn:hover {
  color: var(--danger);
  background: #fee2e2;
}

/* Ad Slot */
.ad-slot {
  background: var(--surface);
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius-md);
  padding: 14px;
  text-align: center;
  position: relative;
}

.ad-badge {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface-alt);
  padding: 1px 5px;
  border-radius: 4px;
}

.ad-placeholder-text {
  font-size: 12px;
  color: var(--text-muted);
}

/* Cross Promo */
.cross-promo {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cross-promo-title {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
}

.promo-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.promo-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  text-decoration: none;
  color: inherit;
  transition: transform 0.12s, border-color 0.12s;
}

.promo-card:hover {
  transform: translateY(-1px);
  border-color: var(--primary);
}

.promo-featured {
  border-color: #bfdbfe;
  background: linear-gradient(135deg, #ffffff 0%, #eff6ff 100%);
}

.promo-emoji {
  font-size: 22px;
}

.promo-info {
  flex: 1;
}

.promo-name {
  font-size: 13px;
  font-weight: 800;
}

.promo-desc {
  font-size: 11px;
  color: var(--text-muted);
}

.promo-arrow {
  font-weight: 800;
  color: var(--primary);
}

/* SEO Table & FAQ */
.guide-section,
.faq-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.faq-heading {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 800;
}

.table-wrap {
  overflow-x: auto;
}

.seo-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.seo-table th,
.seo-table td {
  text-align: left;
  padding: 8px 9px;
  border-bottom: 1px solid var(--border);
}

.seo-table th {
  background: var(--surface-alt);
  color: var(--text-muted);
  font-weight: 700;
}

.seo-table code {
  background: var(--primary-soft);
  color: var(--primary);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 11px;
}

.faq-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.faq-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  background: var(--surface-alt);
}

.faq-q {
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.faq-a {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* Footer */
.tool-footer {
  text-align: center;
  padding: 20px 16px 8px;
  color: var(--text-muted);
  font-size: 12px;
}

.footer-links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 8px;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
}

.footer-links a:hover {
  color: var(--primary);
}

.footer-copy {
  margin: 0;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 999px;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
}

@media (max-width: 440px) {
  .unit-cat-row {
    grid-template-columns: repeat(2, 1fr);
  }
  .unit-converter-grid {
    grid-template-columns: 1fr;
  }
  .unit-arrow {
    text-align: center;
    padding: 0;
    transform: rotate(90deg);
  }
}
