/*
 * guid.enso.no: styled with the Ensō design system (style.enso.no).
 * All design values come from css/tokens.css. The few app-level tokens
 * below are derived from those tokens rather than hard-coded.
 */

/* Declared on every theme container so derived values are recomputed per theme
   (custom properties resolve where they are declared, then inherit). */
:root,
.theme-dark,
.theme-brand {
  /* App tokens, derived from Ensō tokens so they follow every theme. */
  --app-muted: color-mix(in srgb, var(--theme-text) 72%, var(--theme-background));
  --app-surface: color-mix(in srgb, var(--theme-text) 4%, var(--theme-background));
  --app-hover: color-mix(in srgb, var(--theme-text) 8%, var(--theme-background));
  --app-focus: var(--brand-600);
  --app-error: var(--error-400);
  --app-content-width: 880px;
  color-scheme: light;
}

html.theme-dark {
  --app-error: var(--brand-warm); /* --error-400 is too low-contrast on rose */
  color-scheme: dark;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--theme-background);
  color: var(--theme-text);
  font-family: var(--font-sans);
  font-size: var(--font-size-text-main);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-relaxed);
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: calc(var(--app-content-width) + 2 * var(--site-margin));
  margin: 0 auto;
  padding: 0 var(--site-margin);
}

.mono {
  font-family: var(--font-mono);
}
.dim {
  color: var(--app-muted);
}
.small {
  font-size: var(--font-size-text-small);
  font-weight: var(--font-weight-book);
}
[hidden] {
  display: none !important;
}
svg {
  flex: none;
}

:focus-visible {
  outline: 3px solid var(--app-focus);
  outline-offset: 2px;
}

/* ---------- header ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--nav-height);
  padding: var(--space-3) 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--theme-text);
  font-family: var(--font-mono);
  font-weight: var(--font-weight-book);
  font-size: var(--font-size-text-main);
  text-transform: uppercase;
  text-decoration: none;
}
.brand svg {
  width: 32px;
  height: 32px;
}
.brand:hover span {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.icon-btn {
  appearance: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-round);
  border: var(--border-width-main) solid var(--btn-secondary-border);
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--app-hover);
}
.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* ---------- intro ---------- */

.intro {
  margin: var(--space-6) 0 var(--space-6);
}
.intro h1 {
  margin: 0 0 var(--space-2);
  font-size: var(--font-size-h1);
  line-height: var(--line-height-base);
  letter-spacing: var(--letter-spacing-h1);
  font-weight: var(--font-weight-semibold);
}
.intro p {
  margin: 0;
  max-width: 60ch;
  font-size: var(--font-size-text-large);
  color: var(--app-muted);
}
.intro .aka {
  margin-bottom: var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--font-size-text-main);
  font-weight: var(--font-weight-book);
  color: var(--theme-text);
}

/* ---------- cards ---------- */

.card {
  background: var(--theme-background);
  color: var(--theme-text);
  border: var(--border-width-main) solid var(--theme-border);
  border-radius: var(--radius-main);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}

.card h2 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--font-size-text-small);
  font-weight: var(--font-weight-book);
  line-height: var(--line-height-relaxed);
  letter-spacing: var(--letter-spacing-none);
  text-transform: uppercase;
}

.tag {
  display: inline-block;
  padding: 2px var(--space-2);
  border-radius: var(--radius-round);
  background: var(--brand-warm);
  color: var(--dark-900);
  font-family: var(--font-mono);
  font-size: var(--font-size-label);
  font-weight: var(--font-weight-book);
  text-transform: none;
}

.lead {
  margin: calc(-1 * var(--space-2)) 0 var(--space-4);
}

/* ---------- hero (Ensō brand theme) ---------- */

.hero {
  padding: var(--space-6) var(--space-5) var(--space-5);
  text-align: center;
  border-color: var(--theme-border);
}

.seg {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-1);
}
.seg button {
  appearance: none;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-round);
  border: var(--border-width-main) solid var(--btn-secondary-border);
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  font-family: var(--font-mono);
  font-size: var(--font-size-text-small);
  font-weight: var(--font-weight-book);
  line-height: var(--line-height-relaxed);
  cursor: pointer;
}
.seg button small {
  font-size: var(--font-size-label);
  margin-left: 2px;
}
.seg button:hover {
  background: var(--app-hover);
}
.seg button[aria-pressed='true'] {
  background: var(--dark-900);
  border-color: var(--dark-900);
  color: var(--light-100);
}

.guid {
  margin: var(--space-6) auto var(--space-2);
  padding: var(--space-2) var(--space-3);
  max-width: 100%;
  border-radius: var(--radius-small);
  font-family: var(--font-mono);
  font-weight: var(--font-weight-book);
  /* DejaVu Sans Mono advance is ~0.6em: 36 chars ≈ 21.7em, so 3.5vw fits a phone */
  font-size: clamp(12px, 3.5vw, var(--font-size-h4));
  line-height: var(--line-height-base);
  overflow-wrap: anywhere;
  cursor: copy;
  user-select: all;
  -webkit-user-select: all;
  min-height: calc(1.3em + 2 * var(--space-2));
}
.guid:hover {
  background: color-mix(in srgb, var(--theme-text) 6%, transparent);
}

/* Version and variant nibbles */
.guid .ver,
.guid .var,
.meta .legend-ver,
.meta .legend-var {
  border-radius: 4px;
  color: var(--dark-900);
}
.guid .ver,
.meta .legend-ver {
  background: var(--brand-600);
}
.guid .var,
.meta .legend-var {
  background: var(--mauve-400);
}
.meta .legend-ver,
.meta .legend-var {
  padding: 0 6px;
}

.flash {
  animation: flash 0.7s ease-out;
}
@keyframes flash {
  0% {
    background: color-mix(in srgb, var(--brand-600) 45%, transparent);
  }
  100% {
    background: transparent;
  }
}

.meta {
  margin: 0 0 var(--space-4);
  min-height: 1.5em;
  font-family: var(--font-mono);
  font-size: var(--font-size-text-small);
  font-weight: var(--font-weight-book);
  color: var(--app-muted);
}

/* ---------- buttons ---------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
}
.actions.start {
  justify-content: flex-start;
  margin-top: var(--space-3);
}

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-round);
  border: var(--border-width-main) solid var(--btn-secondary-border);
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  font-family: var(--font-sans);
  font-size: var(--font-size-text-main);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-base);
  cursor: pointer;
  transition: background-color 0.15s, transform 0.08s;
}
.btn:hover {
  background: var(--app-hover);
}
.btn:active {
  transform: translateY(1px);
}
.btn svg {
  width: 16px;
  height: 16px;
}
.btn.primary {
  background: var(--btn-primary-bg);
  border-color: var(--btn-primary-border);
  color: var(--btn-primary-text);
}
.btn.primary:hover {
  background: color-mix(in srgb, var(--btn-primary-bg) 85%, var(--theme-text));
}

kbd {
  font-family: var(--font-mono);
  font-size: var(--font-size-label);
  font-weight: var(--font-weight-book);
  padding: 0 6px;
  border-radius: 4px;
  border: 1px solid currentColor;
  opacity: 0.75;
}

.recent {
  list-style: none;
  margin: var(--space-4) 0 0;
  padding: var(--space-3) 0 0;
  border-top: var(--border-width-main) dashed var(--theme-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.recent button {
  appearance: none;
  border: 0;
  background: none;
  padding: 2px var(--space-2);
  border-radius: var(--radius-small);
  font-family: var(--font-mono);
  font-size: var(--font-size-text-small);
  font-weight: var(--font-weight-book);
  color: var(--app-muted);
  overflow-wrap: anywhere;
  cursor: copy;
}
.recent button:hover {
  color: var(--theme-text);
  background: color-mix(in srgb, var(--theme-text) 6%, transparent);
}

/* ---------- forms (Ensō skjemaer) ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  align-items: end;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-3) var(--space-4);
}
.row > .field {
  flex: 1 1 160px;
}
.row > .field.grow {
  flex: 3 1 240px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
  font-size: var(--font-size-text-small);
  font-weight: var(--font-weight-semibold);
}

select,
input[type='text'],
input[type='number'],
textarea {
  width: 100%;
  min-width: 0;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-small);
  border: var(--border-width-main) solid var(--theme-border);
  background: var(--app-surface);
  color: var(--theme-text);
  font-family: var(--font-sans);
  font-size: var(--font-size-text-main);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-base);
}
select:hover,
input:hover,
textarea:hover {
  border-color: var(--theme-text);
}
select:focus,
input:focus,
textarea:focus {
  outline: 3px solid var(--app-focus);
  outline-offset: 0;
  border-color: var(--theme-text);
}
input.mono,
textarea {
  font-family: var(--font-mono);
  font-weight: var(--font-weight-book);
}
::placeholder {
  color: var(--app-muted);
  opacity: 1;
}

select {
  appearance: none;
  padding-right: var(--space-6);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

textarea {
  display: block;
  margin-top: var(--space-4);
  min-height: 200px;
  resize: vertical;
  font-size: var(--font-size-text-small);
  line-height: var(--line-height-relaxed);
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
}

.big-input {
  font-size: var(--font-size-text-main) !important;
  padding: var(--space-3) !important;
}

.switch {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  font-size: var(--font-size-text-main);
  cursor: pointer;
  user-select: none;
}
.switch input {
  appearance: none;
  position: relative;
  flex: none;
  width: 44px;
  height: 24px;
  margin: 0;
  border-radius: var(--radius-round);
  border: var(--border-width-main) solid var(--theme-border);
  background: var(--app-surface);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}
.switch input::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--theme-border);
  transition: transform 0.15s, background-color 0.15s;
}
.switch input:checked {
  background: var(--btn-primary-bg);
  border-color: var(--btn-primary-border);
}
.switch input:checked::after {
  background: var(--btn-primary-text);
  transform: translateX(20px);
}

/* ---------- v5 / inspect output ---------- */

.out {
  margin-top: var(--space-4);
  padding: var(--space-3);
  min-height: 56px;
  border-radius: var(--radius-small);
  border: var(--border-width-main) dashed var(--theme-border);
  font-family: var(--font-mono);
  font-weight: var(--font-weight-book);
  overflow-wrap: anywhere;
  cursor: copy;
}
.out:hover {
  background: var(--app-hover);
}
.out.empty {
  color: var(--app-muted);
  cursor: default;
  font-family: var(--font-sans);
}
.out.empty:hover {
  background: none;
}
.out.error,
.err {
  color: var(--app-error);
}

#inspectMsg {
  margin: var(--space-1) 0 0;
}

.kv {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 2px var(--space-4);
  margin: var(--space-4) 0 0;
}
.kv:empty {
  display: none;
}
.kv dt {
  padding: 6px 0;
  font-size: var(--font-size-text-small);
  color: var(--app-muted);
}
.kv dd {
  margin: 0;
  min-width: 0;
}
.kv dd > * {
  display: block;
  width: 100%;
  padding: 6px var(--space-1);
  border-radius: var(--radius-small);
  font-family: var(--font-mono);
  font-size: var(--font-size-text-small);
  font-weight: var(--font-weight-book);
  line-height: var(--line-height-relaxed);
  text-align: left;
  overflow-wrap: anywhere;
  color: var(--theme-text);
}
.kv dd > button {
  appearance: none;
  border: 0;
  background: none;
  cursor: copy;
}
.kv dd > button:hover {
  background: var(--app-hover);
}
.kv dd .note {
  font-family: var(--font-sans);
  font-weight: var(--font-weight-semibold);
}
.kv .section {
  grid-column: 1 / -1;
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: var(--border-width-main) solid var(--theme-border);
}

.pill {
  display: inline-block;
  margin-right: var(--space-1);
  padding: 0 var(--space-1);
  border-radius: var(--radius-round);
  background: var(--brand-600);
  color: var(--dark-900);
  font-family: var(--font-mono);
  font-weight: var(--font-weight-book);
}

/* ---------- footer & toast ---------- */

footer {
  padding: var(--space-5) 0 var(--space-8);
  text-align: center;
  font-family: var(--font-mono);
  font-size: var(--font-size-text-small);
  font-weight: var(--font-weight-book);
  color: var(--app-muted);
}
footer p {
  margin: var(--space-1) 0;
}

/* Ensō footer link + CTA arrow */
.credit {
  margin-top: var(--space-5) !important;
  padding-top: var(--space-4);
  border-top: var(--border-width-main) solid var(--theme-border);
  font-size: var(--font-size-text-main);
  color: var(--theme-text);
}
.credit a {
  color: var(--theme-text);
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: var(--border-width-main);
}
.credit .arrow {
  display: inline-block;
  margin-left: var(--space-1);
  text-decoration: none;
  transition: transform 0.15s;
}
.credit a:hover .arrow {
  transform: translateX(4px);
}
.private {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}
.private svg {
  width: 14px;
  height: 14px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: var(--space-4);
  max-width: calc(100vw - 2 * var(--site-gutter));
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-round);
  background: var(--theme-text);
  color: var(--theme-background);
  font-family: var(--font-mono);
  font-size: var(--font-size-text-small);
  font-weight: var(--font-weight-book);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transform: translate(-50%, 16px);
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}
#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- small screens ---------- */

@media (max-width: 720px) {
  .wrap {
    padding: 0 var(--site-gutter);
  }
  .intro {
    margin: var(--space-3) 0 var(--space-5);
  }
  .intro h1 {
    font-size: var(--font-size-h4);
  }
  .intro p {
    font-size: var(--font-size-text-main);
  }
  .card {
    padding: var(--space-4) var(--space-3);
  }
  .hero {
    padding: var(--space-5) var(--space-2) var(--space-4);
  }
  .seg button small {
    display: none;
  }
  .guid {
    padding: var(--space-2) 4px;
  }
  .kv {
    grid-template-columns: minmax(0, 1fr);
  }
  .kv dt {
    padding-bottom: 0;
  }
  .keys {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
