/* =========================================================================
   Crypto Playground — theme + layout
   ========================================================================= */

:root {
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --radius: 12px;
  --radius-sm: 8px;
  --topbar-h: 64px;
  --maxw: 1180px;
}

/* ---- light theme (default) ------------------------------------------------ */
:root,
:root[data-theme="light"] {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #14171f;
  --text-muted: #5a6472;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(79, 70, 229, 0.1);
  --ok: #067647;
  --ok-bg: #e7f6ee;
  --bad: #b42318;
  --bad-bg: #fdeceb;
  --warn: #b54708;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  --shadow-lg: 0 6px 24px rgba(16, 24, 40, 0.1);
  --topbar-bg: rgba(255, 255, 255, 0.82);
  color-scheme: light;
}

/* ---- dark theme ----------------------------------------------------------- */
:root[data-theme="dark"] {
  --bg: #0b0e13;
  --surface: #141a22;
  --surface-2: #1b222c;
  --border: #262e39;
  --border-strong: #364150;
  --text: #e6edf3;
  --text-muted: #98a3b2;
  --accent: #818cf8;
  --accent-hover: #a5adfb;
  --accent-contrast: #0b0e13;
  --accent-soft: rgba(129, 140, 248, 0.16);
  --ok: #5fd79c;
  --ok-bg: rgba(38, 142, 95, 0.18);
  --bad: #ff958d;
  --bad-bg: rgba(180, 35, 24, 0.22);
  --warn: #f0a960;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
  --topbar-bg: rgba(15, 20, 27, 0.82);
  color-scheme: dark;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-h) + 16px);
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

code {
  font-family: var(--font-mono);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---- loader --------------------------------------------------------------- */
.loader {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: var(--bg);
  z-index: 100;
}
.loader__spinner {
  width: 42px;
  height: 42px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.loader__text {
  color: var(--text-muted);
  font-size: 0.95rem;
}
.loader__error {
  max-width: 460px;
  text-align: center;
  padding: 0 24px;
}
.loader__error h2 {
  color: var(--bad);
}
.loader__error p {
  color: var(--text-muted);
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---- topbar --------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  background: var(--topbar-bg);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar__inner {
  height: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-right: auto;
}
.brand__mark {
  font-size: 1.6rem;
  line-height: 1;
}
.brand__text {
  display: flex;
  flex-direction: column;
}
.brand__title {
  font-weight: 650;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.brand__sub {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.theme-toggle {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 1.1rem;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.theme-toggle:hover {
  border-color: var(--border-strong);
}
.theme-toggle:active {
  transform: scale(0.94);
}

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 550;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.ghost-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.ghost-btn i {
  font-size: 0.95rem;
}

/* ---- app shell ------------------------------------------------------------ */
.app {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 8px 24px 64px;
}

/* ---- tabs ----------------------------------------------------------------- */
.tabs {
  position: sticky;
  top: var(--topbar-h);
  z-index: 20;
  display: flex;
  gap: 4px;
  margin-bottom: 26px;
  padding: 8px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: thin;
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  flex: 0 0 auto;
  padding: 9px 15px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 550;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab:hover {
  background: var(--surface-2);
  color: var(--text);
}
.tab--active,
.tab--active:hover {
  color: var(--accent);
  background: var(--accent-soft);
}
.tab__icon {
  font-size: 0.92rem;
  width: 1.1em;
  text-align: center;
}

/* ---- panels --------------------------------------------------------------- */
.panels {
  min-width: 0;
}
.panel[hidden] {
  display: none;
}
.panel {
  animation: fade-in 0.22s ease;
}
@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 20px;
}

/* ---- card ----------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}
.card:hover {
  box-shadow: var(--shadow-lg);
}
.card__head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.card__icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--accent);
  background: var(--accent-soft);
}
.card__title {
  font-size: 1.02rem;
  font-weight: 640;
  margin: 0;
  margin-right: auto;
}
.card__desc {
  margin: -6px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ---- badges --------------------------------------------------------------- */
.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  text-transform: lowercase;
  white-space: nowrap;
}
.badge--mixed {
  color: var(--text-muted);
  background: var(--surface-2);
  border-color: var(--border);
}
.badge--cryptoxide {
  color: #6d28d9;
  background: rgba(124, 58, 237, 0.12);
  border-color: rgba(124, 58, 237, 0.25);
}
.badge--eccoxide {
  color: #0e7490;
  background: rgba(6, 148, 178, 0.12);
  border-color: rgba(6, 148, 178, 0.25);
}
:root[data-theme="dark"] .badge--cryptoxide {
  color: #c4b5fd;
}
:root[data-theme="dark"] .badge--eccoxide {
  color: #67e8f9;
}

/* ---- fields --------------------------------------------------------------- */
.card__fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
/* `display: flex` above would otherwise defeat the [hidden] attribute used for
   conditional fields (e.g. the ECDSA nonce, hidden for Ed25519). */
.field[hidden] {
  display: none;
}
.field__labelrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.field__label {
  font-size: 0.82rem;
  font-weight: 560;
  color: var(--text);
}
.field__tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.control {
  width: 100%;
  padding: 9px 11px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.control:hover {
  border-color: var(--border-strong);
}
.control:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea.control {
  resize: vertical;
  min-height: 44px;
  line-height: 1.5;
}
.mono {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  word-break: break-all;
}
.select {
  cursor: pointer;
}

.encsel {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 3px 6px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.field__hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  min-height: 1em;
}
.field__hint--warn {
  color: var(--warn);
}
.field__hint--error {
  color: var(--bad);
}

/* ---- buttons -------------------------------------------------------------- */
.iconbtn {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 3px 8px;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.iconbtn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.btn {
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 560;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}
.btn:active {
  transform: translateY(1px);
}
.btn--primary {
  background: var(--accent);
  color: var(--accent-contrast);
}
.btn--primary:hover {
  background: var(--accent-hover);
}
.btn--secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn--secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---- error + outputs ------------------------------------------------------ */
.card__error {
  padding: 10px 12px;
  font-size: 0.82rem;
  color: var(--bad);
  background: var(--bad-bg);
  border: 1px solid var(--bad);
  border-radius: var(--radius-sm);
}

.card__outputs:empty {
  display: none;
}
.card__outputs {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.output {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.output__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.output__label {
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  text-transform: uppercase;
}
.output__hex {
  display: block;
  color: var(--text);
  font-size: 0.84rem;
  line-height: 1.6;
  word-break: break-all;
}
.output__utf8 {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  font-size: 0.82rem;
  color: var(--text);
}
.output__utf8-label {
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  flex-shrink: 0;
}

.result-badge {
  align-self: flex-start;
  font-size: 0.9rem;
  font-weight: 640;
  padding: 6px 14px;
  border-radius: 999px;
}
.result-badge--ok {
  color: var(--ok);
  background: var(--ok-bg);
}
.result-badge--bad {
  color: var(--bad);
  background: var(--bad-bg);
}

/* ---- about dialog --------------------------------------------------------- */
.dialog {
  width: min(560px, calc(100vw - 32px));
  padding: 26px 28px 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.dialog::backdrop {
  background: rgba(8, 11, 16, 0.55);
  backdrop-filter: blur(3px);
}
.dialog__title {
  font-size: 1.2rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 0 0 14px;
}
.dialog p {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0 0 14px;
}
.dialog p strong {
  color: var(--text);
}
.dialog a {
  font-weight: 550;
}
.dialog__meta {
  font-size: 0.82rem;
}
.dialog__closer {
  position: absolute;
  top: 14px;
  right: 14px;
  margin: 0;
}
.dialog__close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.dialog__close:hover {
  background: var(--surface-2);
  color: var(--text);
}
.dialog__actions {
  display: flex;
  justify-content: flex-end;
  margin: 4px 0 0;
}

/* ---- callouts ------------------------------------------------------------- */
.callout {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin: 0 0 14px;
}
.callout p {
  margin: 0;
  font-size: 0.84rem;
}
.callout i {
  flex-shrink: 0;
  margin-top: 2px;
  font-size: 1rem;
}
.callout--info {
  background: var(--accent-soft);
  border-color: transparent;
}
.callout--info i {
  color: var(--accent);
}
.callout--warn {
  background: var(--bad-bg);
  border-color: transparent;
}
.callout--warn i {
  color: var(--bad);
}

/* ---- responsive ----------------------------------------------------------- */
@media (max-width: 860px) {
  .card-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .brand__sub {
    display: none;
  }
}

@media (max-width: 480px) {
  .topbar__inner,
  .app {
    padding-left: 16px;
    padding-right: 16px;
  }
  .tabs {
    /* let the sticky tab bar span the full width so it can scroll edge-to-edge */
    margin-left: -16px;
    margin-right: -16px;
    padding-left: 16px;
    padding-right: 16px;
  }
  .ghost-btn span {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto;
    transition: none !important;
    animation-duration: 0.01ms !important;
  }
}
