:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #253347;
  --border: rgba(59, 130, 246, 0.15);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-dim: #60a5fa;
  --danger: #ef4444;
  --radius: 12px;
  --font: "IBM Plex Sans", "IBM Plex Sans Thai", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--text);
  background: radial-gradient(1200px 600px at 10% -10%, #1a3d38 0%, transparent 50%),
    radial-gradient(900px 500px at 100% 0%, #1e2a4a 0%, transparent 45%), var(--bg);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  z-index: 100;
}

.skip-link:focus {
  left: 0.5rem;
}

.site-header {
  border-bottom: 1px solid var(--border);
  background: rgba(15, 20, 25, 0.85);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.logo {
  margin: 0;
  font-size: clamp(1.1rem, 2.5vw, 1.35rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.lang-toggle {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.lang-toggle:hover {
  border-color: var(--accent-dim);
  background: var(--surface);
}

.lang-toggle[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.ad-slot {
  max-width: 880px;
  margin: 1rem auto;
  padding: 0 1.25rem;
}

.ad-placeholder {
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.85rem;
}

.main {
  max-width: 880px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.lead {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 1.05rem;
  max-width: 62ch;
}

.mode-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.mode-tab {
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.mode-tab:hover {
  color: var(--text);
  border-color: var(--muted);
}

.mode-tab.is-active {
  color: var(--bg);
  background: var(--accent);
  border-color: var(--accent);
}

.panels {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}

.calc-panel:not(.is-visible) {
  display: none;
}

.calc-panel.is-visible {
  display: block;
}

.panel-title {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  font-weight: 600;
}

.panel-hint {
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
  margin-bottom: 1.25rem;
}

.field-row--stack {
  flex-direction: column;
  align-items: stretch;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  min-width: 0;
  flex: 1 1 120px;
}

.field--full {
  flex: 1 1 100%;
}

.field span {
  letter-spacing: 0.02em;
}

.field input {
  font-family: inherit;
  font-size: 1.05rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  width: 100%;
}

.field input:focus {
  outline: 2px solid var(--accent-dim);
  outline-offset: 1px;
  border-color: var(--accent-dim);
}

.field-of {
  padding-bottom: 0.65rem;
  font-size: 0.85rem;
  color: var(--muted);
  flex-shrink: 0;
}

.radio-row {
  border: none;
  margin: 0 0 1.25rem;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.radio-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  font-size: 0.875rem;
  cursor: pointer;
}

.radio-pill:has(:checked) {
  border-color: var(--accent);
  color: var(--accent);
}

.radio-pill input {
  accent-color: var(--accent);
}

.result-box {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1rem 1.1rem;
  border-radius: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
}

.result-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.result-value {
  font-size: clamp(1.25rem, 4vw, 1.65rem);
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.result-value.is-error {
  color: var(--danger);
  font-size: 1rem;
}

.history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem 1.25rem;
  margin-bottom: 2rem;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.history-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.btn-text {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  border-radius: 6px;
}

.btn-text:hover {
  text-decoration: underline;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 280px;
  overflow-y: auto;
}

.history-list li {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
  color: var(--text);
}

.history-list li:last-child {
  border-bottom: none;
}

.history-meta {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.history-empty {
  margin: 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.history-empty.is-hidden {
  display: none;
}

.seo-copy {
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
}

.seo-copy h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  color: var(--text);
}

.seo-copy p {
  margin: 0 0 0.75rem;
}

.seo-copy p:last-child {
  margin-bottom: 0;
}

.site-footer {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 1.25rem 2rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
