/* ===================================================================
   Unit Converter — earth87human (cream surface, tomato accent)
   Pill category chips, number inputs, unit selects, swap button.
   =================================================================== */

/* ============ Design tokens ============ */
:root {
  --bg: #faf6f1;
  --bg-2: #f3eee5;
  --surface: #ffffff;
  --surface-2: #faf6ed;
  --surface-3: #eee7d8;
  --border: #e8dfcc;
  --border-soft: #f0e9da;
  --text: #1f1a14;
  --text-2: #5c5547;
  --text-3: #6e6557;
  --text-faint: #b5ac9b;
  --accent: #e85f4d;
  --accent-2: #d44a39;
  --accent-soft: rgba(232, 95, 77, 0.10);
  --accent-glow: rgba(232, 95, 77, 0.30);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 24px 48px rgba(0,0,0,0.12);

  --font-ui: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI",
             "PingFang TC", "PingFang SC", "Hiragino Sans", "Noto Sans CJK",
             sans-serif;
  --font-mono: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============ Reset ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
html, body {
  font-family: var(--font-ui);
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(255, 235, 220, 0.55) 0%, transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.55;
  touch-action: manipulation;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font-family: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-2); }
ul, ol { list-style: none; }
[hidden] { display: none !important; }

/* Skip link */
.skip-link {
  position: absolute;
  left: -9999px; top: 0;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  font-weight: 600;
  border-radius: 0 0 var(--r-sm) 0;
  z-index: 1000;
}
.skip-link:focus { left: 0; }

/* ============ App layout ============ */
.app {
  max-width: 640px;
  margin: 0 auto;
  padding: clamp(12px, 3vw, 24px) clamp(12px, 3vw, 24px) 80px;
}

/* ============ Top bar ============ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 4px 28px;
}
.brand {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--text-2);
}
.brand:hover { color: var(--accent); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-link {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-3);
  padding: 6px 10px;
  border-radius: var(--r-sm);
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}
@media (max-width: 380px) {
  .nav-link { font-size: 12px; padding: 4px 8px; }
}
.nav-link:hover { color: var(--accent); background: var(--surface-2); }

.lang-switcher {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 28px 6px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 12 12' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3 5l3 3 3-3' stroke='%237a7973' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 12px;
  transition: border-color var(--transition);
}
.lang-switcher:hover { border-color: var(--text-3); }
.lang-switcher:focus { outline: 2px solid var(--accent); outline-offset: 2px; border-color: var(--accent); }

/* ============ Page title ============ */
.page-title {
  font-size: clamp(24px, 4vw, 32px);
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: center;
  margin-bottom: 6px;
}
.page-sub {
  text-align: center;
  font-size: 14px;
  color: var(--text-3);
  margin-bottom: 36px;
}

/* ============ Workspace ============ */
.workspace {
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin-bottom: 64px;
}

/* ============ Category chips ============ */
.category-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.chip {
  padding: 8px 18px;
  min-height: 44px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chip-active:hover { color: #fff; }
@media (max-width: 380px) {
  .chip { padding: 7px 14px; font-size: 12px; }
}

/* ============ Converter ============ */
.converter {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: clamp(20px, 4vw, 32px) clamp(20px, 5vw, 32px);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.6),
    0 4px 12px rgba(0,0,0,0.05),
    0 14px 32px rgba(120, 90, 60, 0.10);
}

/* ============ Converter row (inputs + swap) ============ */
.converter-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.input-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-3);
  font-weight: 600;
}

/* ============ Number input ============ */
.number-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text);
  font-size: clamp(16px, 3vw, 20px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  text-align: right;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: textfield;
  -webkit-appearance: textfield;
  -moz-appearance: textfield;
}
.number-input::-webkit-inner-spin-button,
.number-input::-webkit-outer-spin-button { display: none; }
.number-input:hover { border-color: var(--text-3); }
.number-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.number-input[readonly] {
  background: var(--surface);
  color: var(--text-2);
  cursor: default;
}

/* ============ Unit select ============ */
.unit-select {
  width: 100%;
  padding: 10px 28px 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 12 12' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3 5l3 3 3-3' stroke='%237a7973' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px;
  transition: border-color var(--transition);
}
.unit-select:hover { border-color: var(--text-3); }
.unit-select:focus { outline: 2px solid var(--accent); outline-offset: 2px; border-color: var(--accent); }

/* ============ Swap button ============ */
.swap-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-3);
  margin-bottom: 1px;
  transition: all var(--transition);
}
.swap-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  transform: rotate(180deg);
}
.swap-btn:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============ Result row ============ */
.result-row {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.result-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-3);
  font-weight: 600;
}

.result-equals {
  font-size: 14px;
  color: var(--text-faint);
  font-weight: 500;
  flex-shrink: 0;
}

.result-value {
  font-family: var(--font-mono);
  font-size: clamp(18px, 4vw, 24px);
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
  word-break: break-all;
}

/* ============ Info section ============ */
.info {
  margin-top: clamp(32px, 6vw, 56px);
}
.info h2 {
  font-size: clamp(18px, 3.5vw, 20px);
  font-weight: 700;
  color: var(--text);
  margin: 32px 0 12px;
  letter-spacing: -0.01em;
}
.info h2:first-child { margin-top: 0; }
.info p {
  font-size: clamp(14px, 3.6vw, 15px);
  line-height: 1.75;
  color: var(--text-2);
}

/* ============ Footer ============ */
.site-footer {
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--border-soft);
  text-align: center;
}
.site-footer-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  font-size: 13px;
  color: var(--text-3);
}
.site-footer a {
  color: var(--text-3);
  text-decoration: none;
  transition: color var(--transition);
}
.site-footer a:hover { color: var(--accent); }
.site-footer .sub {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-3);
}

/* ============ Reduced motion ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============ RWD ============ */
@media (max-width: 600px) {
  .topbar { padding: 4px 0 20px; }
}
@media (max-width: 480px) {
  .converter-row {
    flex-direction: column;
    gap: 16px;
  }
  .swap-btn {
    align-self: center;
    transform: rotate(90deg);
    margin-bottom: 0;
  }
  .swap-btn:hover { transform: rotate(270deg); }
}
@media (max-width: 420px) {
  .topbar-right .nav-link { display: none; }
  .topbar-right { gap: 6px; }
  .lang-switcher { max-width: 130px; font-size: 12px; padding: 4px 22px 4px 8px; }
}

/* ============ Focus visible ============ */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus:not(:focus-visible),
select:focus:not(:focus-visible),
input:focus:not(:focus-visible) { outline: none; }
