:root {
  color-scheme: light;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: #dbe3ee;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning: #b45309;
  --shadow: 0 20px 50px rgba(15, 23, 42, .08);
  --radius: 22px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #08111f;
  --surface: #101b2d;
  --surface-soft: #17243a;
  --text: #e8eef7;
  --muted: #9caec4;
  --border: #293b55;
  --primary: #60a5fa;
  --primary-dark: #3b82f6;
  --primary-soft: #142b4d;
  --success: #4ade80;
  --success-soft: #123522;
  --danger: #fb7185;
  --danger-soft: #3d1720;
  --warning: #fbbf24;
  --shadow: 0 22px 60px rgba(0, 0, 0, .26);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 12% 5%, rgba(37, 99, 235, .10), transparent 24rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  transition: background .25s ease, color .25s ease;
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
.container { width: min(1120px, calc(100% - 32px)); margin-inline: auto; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 100; transform: translateY(-140%); background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: 10px; }
.skip-link:focus { transform: translateY(0); }

.app-header { position: sticky; top: 0; z-index: 20; border-bottom: 1px solid color-mix(in srgb, var(--border) 80%, transparent); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(18px); }
.header-content { min-height: 76px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; gap: 12px; align-items: center; color: var(--text); text-decoration: none; }
.brand-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 14px; color: white; background: linear-gradient(135deg, var(--primary), #7c3aed); box-shadow: 0 10px 24px rgba(37, 99, 235, .28); font-weight: 900; }
.brand strong, .brand small { display: block; line-height: 1.05; }
.brand strong { font-size: 1.02rem; }
.brand small { margin-top: 4px; color: var(--muted); }
.icon-button { width: 44px; height: 44px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); font-size: 1.25rem; transition: .2s ease; }
.icon-button:hover { transform: translateY(-2px); border-color: var(--primary); }

.main-content { padding-block: 58px 72px; }
.hero { max-width: 780px; margin: 0 auto 36px; text-align: center; }
.eyebrow, .panel-kicker { display: inline-block; color: var(--primary); font-size: .78rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.hero h1 { margin: 12px 0 14px; font-size: clamp(2rem, 5vw, 3.7rem); line-height: 1.05; letter-spacing: -.045em; }
.hero p { margin: 0; color: var(--muted); font-size: clamp(1rem, 2vw, 1.13rem); }

.workspace { max-width: 820px; margin: 0 auto 58px; }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); padding: 6px; gap: 6px; border: 1px solid var(--border); border-radius: 17px; background: var(--surface-soft); margin-bottom: 14px; }
.tab { border: 0; border-radius: 12px; padding: 13px; color: var(--muted); background: transparent; font-weight: 800; transition: .2s ease; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); background: var(--surface); box-shadow: 0 6px 18px rgba(15, 23, 42, .08); }
.panel-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.tool-panel { padding: clamp(24px, 5vw, 42px); animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 28px; }
.panel-heading h2, .section-heading h2 { margin: 5px 0 0; font-size: clamp(1.45rem, 3vw, 2rem); letter-spacing: -.025em; }
.panel-badge { padding: 7px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: .76rem; font-weight: 800; white-space: nowrap; }

.type-selector { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0 0 20px; padding: 0; border: 0; }
.type-selector legend { grid-column: 1 / -1; margin-bottom: 8px; font-weight: 800; }
.choice-card { position: relative; display: flex; align-items: center; gap: 12px; min-height: 74px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface-soft); cursor: pointer; transition: .2s ease; }
.choice-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.choice-card:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 13%, transparent); }
.choice-card input { width: 18px; height: 18px; accent-color: var(--primary); }
.choice-card strong, .choice-card small { display: block; }
.choice-card small { color: var(--muted); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px; border: 1px solid var(--border); border-radius: 16px; margin-bottom: 20px; }
.switch-row strong, .switch-row small { display: block; }
.switch-row small { color: var(--muted); }
.switch { position: relative; flex: 0 0 auto; width: 52px; height: 30px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { display: block; width: 100%; height: 100%; border-radius: 999px; background: #94a3b8; transition: .2s ease; }
.switch span::after { content: ""; position: absolute; top: 4px; left: 4px; width: 22px; height: 22px; border-radius: 50%; background: white; box-shadow: 0 2px 8px rgba(0,0,0,.2); transition: .2s ease; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(22px); }
.switch input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--primary) 30%, transparent); outline-offset: 3px; }

.result-box { display: grid; grid-template-columns: 1fr auto; gap: 5px 16px; align-items: center; padding: 18px; border: 1px dashed color-mix(in srgb, var(--primary) 45%, var(--border)); border-radius: 16px; background: var(--primary-soft); margin-bottom: 18px; }
.result-box > span { grid-column: 1; color: var(--muted); font-size: .8rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.result-box output { grid-column: 1; font-size: clamp(1.25rem, 4vw, 1.7rem); font-weight: 900; letter-spacing: .04em; overflow-wrap: anywhere; }
.copy-button { grid-column: 2; grid-row: 1 / 3; border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; color: var(--text); background: var(--surface); font-weight: 800; }

.primary-button, .secondary-button, .danger-button { min-height: 48px; border-radius: 14px; padding: 12px 18px; font-weight: 800; transition: .2s ease; }
.primary-button { width: 100%; border: 1px solid var(--primary); color: white; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); box-shadow: 0 10px 22px color-mix(in srgb, var(--primary) 25%, transparent); }
.primary-button:hover { transform: translateY(-2px); filter: brightness(1.05); }
.secondary-button { border: 1px solid var(--border); color: var(--text); background: var(--surface); }
.secondary-button:hover { border-color: var(--primary); color: var(--primary); }
.secondary-button.compact { min-height: 46px; padding-inline: 14px; }
.danger-button { border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border)); color: var(--danger); background: var(--danger-soft); }
.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.button-grid .primary-button { width: auto; }

.form-group { margin-bottom: 22px; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 800; }
.form-group small { display: block; margin-top: 7px; color: var(--muted); }
input[type="text"] { width: 100%; min-height: 48px; border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; color: var(--text); background: var(--surface-soft); outline: none; transition: .2s ease; }
input[type="text"]:focus { border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 13%, transparent); }
.input-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.validation-result { display: flex; align-items: center; gap: 14px; padding: 17px; border: 1px solid var(--border); border-radius: 16px; margin-bottom: 18px; }
.validation-result strong { display: block; }
.validation-result p { margin: 3px 0 0; color: var(--muted); }
.validation-icon { display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 auto; border-radius: 50%; background: var(--surface-soft); font-weight: 900; }
.validation-result.success { border-color: color-mix(in srgb, var(--success) 45%, var(--border)); background: var(--success-soft); }
.validation-result.success .validation-icon { color: var(--success); background: color-mix(in srgb, var(--success) 15%, transparent); }
.validation-result.error { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); background: var(--danger-soft); }
.validation-result.error .validation-icon { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }

.history-section { margin-top: 14px; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 20px; }
.section-heading p { margin: 8px 0 0; color: var(--muted); }
.history-list { display: grid; gap: 12px; }
.history-item { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 15px; padding: 16px 18px; border: 1px solid var(--border); border-radius: 17px; background: var(--surface); box-shadow: 0 8px 24px rgba(15, 23, 42, .04); }
.history-marker { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; color: var(--primary); background: var(--primary-soft); font-weight: 900; }
.history-content strong, .history-content small { display: block; }
.history-content code { display: inline-block; margin: 3px 0; color: var(--text); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .98rem; font-weight: 800; }
.history-content small { color: var(--muted); }
.history-status { padding: 6px 10px; border-radius: 999px; font-size: .75rem; font-weight: 800; }
.history-status.valid { color: var(--success); background: var(--success-soft); }
.history-status.invalid { color: var(--danger); background: var(--danger-soft); }
.history-status.info { color: var(--primary); background: var(--primary-soft); }
.empty-state { padding: 38px 20px; border: 1px dashed var(--border); border-radius: 18px; color: var(--muted); background: var(--surface); text-align: center; }
.empty-state strong { display: block; margin-bottom: 4px; color: var(--text); }

.info-card { display: flex; gap: 14px; margin-top: 34px; padding: 20px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface-soft); }
.info-card > span { display: grid; place-items: center; width: 32px; height: 32px; flex: 0 0 auto; border-radius: 50%; color: var(--primary); background: var(--primary-soft); font-weight: 900; }
.info-card p { margin: 4px 0 0; color: var(--muted); }

.toast-container { position: fixed; right: 20px; bottom: 20px; z-index: 50; display: grid; gap: 10px; width: min(360px, calc(100% - 40px)); }
.toast { display: flex; align-items: center; gap: 10px; padding: 13px 15px; border: 1px solid var(--border); border-radius: 14px; color: var(--text); background: var(--surface); box-shadow: var(--shadow); animation: toastIn .25s ease; }
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

.app-footer { padding: 30px 0; border-top: 1px solid var(--border); color: var(--muted); background: var(--surface); }
.footer-content { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.footer-brand { display: grid; gap: 5px; }
.footer-brand strong { color: var(--text); font-size: 1rem; }
.footer-brand span { font-size: .9rem; }
.footer-signature { display: grid; gap: 7px; text-align: right; }
.footer-signature p { margin: 0; }
.footer-signature strong { color: var(--text); }
.footer-links { display: flex; align-items: center; justify-content: flex-end; gap: 9px; }
.footer-links a { color: var(--primary); font-weight: 700; text-decoration: none; }
.footer-links a:hover, .footer-links a:focus-visible { text-decoration: underline; }
@media (max-width: 640px) {
  .footer-content { align-items: flex-start; flex-direction: column; }
  .footer-signature { text-align: left; }
  .footer-links { justify-content: flex-start; }
}

:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 35%, transparent); outline-offset: 3px; }
@media (max-width: 680px) {
  .main-content { padding-top: 38px; }
  .hero { text-align: left; }
  .tool-panel { padding: 24px 18px; }
  .type-selector, .button-grid { grid-template-columns: 1fr; }
  .input-row { grid-template-columns: 1fr; }
  .section-heading { align-items: stretch; flex-direction: column; }
  .danger-button { width: 100%; }
  .history-item { grid-template-columns: auto 1fr; }
  .history-status { grid-column: 2; justify-self: start; }
  .result-box { grid-template-columns: 1fr; }
  .copy-button { grid-column: 1; grid-row: auto; width: 100%; margin-top: 7px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
