@layer components {
  .topbar {
    position: relative;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 56px;
    padding: 6px max(16px, env(safe-area-inset-right)) 6px max(16px, env(safe-area-inset-left));
    background:
      linear-gradient(180deg, rgb(255 255 255 / 0.06), transparent 40%),
      repeating-linear-gradient(92deg, rgb(0 0 0 / 0.07) 0 2px, transparent 2px 9px, rgb(255 255 255 / 0.03) 9px 11px, transparent 11px 23px),
      var(--eiken-dark);
    color: var(--creme);
    box-shadow: inset 0 -1px 0 rgb(201 162 74 / 0.45), 0 2px 10px rgb(0 0 0 / 0.25);
  }

  .topbar__brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    color: inherit;
    text-decoration: none;
  }

  .topbar__mark {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, var(--messing-light), var(--messing) 60%, #a07c2c);
    color: var(--eiken-dark);
    font-size: 1.1rem;
    box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.25);
  }

  .topbar__name {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.25rem;
    letter-spacing: 0.01em;
  }

  .topbar__user {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
  }

  .topbar__who {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--creme-muted);
    font-size: 0.95rem;
  }

  .topbar__turns {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 36px;
    padding: 3px 10px 3px 4px;
    border-radius: 999px;
    background: var(--messing);
    color: var(--inkt);
    font-size: 0.85rem;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
  }

  .topbar__turns:hover { background: var(--messing-light); }

  .topbar__turns-count {
    display: grid;
    place-items: center;
    min-width: 28px;
    height: 28px;
    padding-inline: 6px;
    border-radius: 999px;
    background: var(--eiken-dark);
    color: var(--messing-light);
    font-size: 0.95rem;
  }

  .topbar__away {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 4px 6px;
    color: var(--creme);
    font-size: 0.92rem;
    font-weight: 700;
    white-space: nowrap;
  }

  .topbar__away--on {
    gap: 6px;
    padding-inline: 12px;
    border: 1px solid rgb(242 210 122 / 0.7);
    border-radius: 999px;
    color: var(--messing-light);
    text-decoration: none;
  }

  .topbar__away--on::before { content: "☀"; font-size: 1rem; line-height: 1; }
  .topbar__away--on:hover { background: rgb(242 210 122 / 0.12); }

  .topbar .btn--ghost {
    color: var(--creme);
    border-color: rgb(244 234 213 / 0.55);
  }

  .topbar .btn--ghost:hover { background: rgb(244 234 213 / 0.1); }

  .topbar :focus-visible { outline-color: var(--felt-focus); }

  .main { min-width: 0; }

  .flash-stack {
    position: fixed;
    inset: 64px 0 auto;
    z-index: 50;
    display: grid;
    justify-items: center;
    gap: 8px;
    padding: 0 12px;
    pointer-events: none;
  }

  .flash {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: min(100%, 480px);
    padding: 12px 8px 12px 16px;
    border-radius: var(--radius);
    border-left: 6px solid var(--accent);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-2);
    animation: flash-in 220ms var(--ease-out) both;
  }

  .flash--notice { background: var(--notice-surface); border-left-color: var(--laken); }
  .flash--alert { background: var(--danger-surface); border-left-color: var(--danger); }
  .flash.is-leaving { animation: flash-out 240ms ease-in both; }

  .flash__message { flex: 1; padding-top: 2px; font-weight: 600; }

  .flash__close {
    flex: none;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    font-size: 1.5rem;
    line-height: 1;
  }

  .flash__close:hover { background: rgb(0 0 0 / 0.07); }

  @keyframes flash-in { from { opacity: 0; translate: 0 -12px; } }
  @keyframes flash-out { to { opacity: 0; translate: 0 -12px; } }

  .page {
    width: min(100%, 980px);
    margin-inline: auto;
    padding: clamp(20px, 4vw, 40px) 16px 72px;
  }

  .page--narrow { width: min(100%, 600px); }

  .page__header { margin-bottom: 20px; }
  .page__lead { margin-top: 8px; color: var(--text-muted); font-size: 1.15rem; }

  .panel {
    margin-block: 16px;
    padding: clamp(16px, 3vw, 24px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-1);
  }

  .panel > h2 { margin-bottom: 12px; }
  .panel > p + p { margin-top: 8px; }

  .panel__header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
  }

  .panel--feature,
  .panel--felt {
    position: relative;
    overflow: hidden;
    border: 1px solid rgb(201 162 74 / 0.6);
    background: var(--felt-texture), radial-gradient(ellipse at 30% 20%, var(--laken-light), var(--laken) 55%, var(--laken-deep));
    color: var(--felt-text);
    box-shadow: inset 0 0 0 5px var(--eiken), inset 0 0 0 6px rgb(201 162 74 / 0.5), var(--shadow-2);
    padding: clamp(20px, 4vw, 30px);
  }

  .panel--feature h2,
  .panel--felt h2 { color: var(--schuim); }

  .panel--feature .btn--primary { background: var(--messing); color: var(--inkt); }
  .panel--feature .btn--primary:hover { background: var(--messing-light); }
  .panel--feature .btn--ghost { color: var(--creme); border-color: rgb(244 234 213 / 0.6); }
  .panel--feature .btn--ghost:hover { background: rgb(244 234 213 / 0.1); }
  .panel--feature :focus-visible,
  .panel--felt :focus-visible { outline-color: var(--felt-focus); }

  .list { display: grid; gap: 8px; }

  .list__item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-sunk);
  }

  .list__link,
  .list__item--static {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 12px;
    min-height: 52px;
    padding: 10px 16px;
  }

  .list__link {
    border-radius: inherit;
    color: inherit;
    text-decoration: none;
    transition: background-color 150ms;
  }

  .list__link:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }

  .list__title { flex: 1; font-weight: 700; }
  .list__meta { order: 3; flex-basis: 100%; color: var(--text-muted); font-size: 0.95rem; }

  .badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 26px;
    padding: 2px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    color: var(--text);
    font-size: 0.85rem;
    font-weight: 700;
    white-space: nowrap;
  }

  .badge--open { border-color: transparent; background: var(--accent); color: var(--accent-text); }

  .badge--turn {
    border-color: transparent;
    background: var(--messing);
    color: var(--inkt);
    white-space: normal;
  }

  .badge--turn time { font-weight: 600; }

  .badge--mode { border-style: dashed; font-weight: 600; }

  .list__badges {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
  }

  @media (max-width: 559.98px) {
    .list__badges { order: 2; flex-basis: 100%; justify-content: flex-start; }
  }

  .list__item--turn {
    border-color: var(--messing);
    box-shadow: inset 5px 0 0 var(--messing);
    background: color-mix(in srgb, var(--messing) 12%, var(--surface));
  }

  .list__item--turn .list__link { padding-left: 20px; }

  .turn-summary {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    padding: 6px 16px 6px 6px;
    border-radius: 22px;
    background: color-mix(in srgb, var(--messing) 22%, var(--surface));
    font-weight: 700;
  }

  .turn-summary__count {
    display: grid;
    place-items: center;
    min-width: 32px;
    height: 32px;
    border-radius: 999px;
    background: var(--messing);
    color: var(--inkt);
  }

  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    padding: 10px 20px;
    border: 2px solid transparent;
    border-radius: 12px;
    font-family: var(--font-ui);
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 150ms, border-color 150ms, translate 150ms var(--ease-out), box-shadow 150ms;
  }

  .btn:active:not(:disabled) { translate: 0 1px; }
  .btn:disabled { opacity: 0.55; cursor: not-allowed; }

  .btn--primary {
    background: var(--accent);
    color: var(--accent-text);
    box-shadow: 0 1px 0 rgb(255 255 255 / 0.15) inset, 0 2px 6px rgb(0 0 0 / 0.15);
  }

  .btn--primary:hover:not(:disabled) { background: var(--accent-hover); }

  .btn--ghost {
    background: transparent;
    color: var(--text);
    border-color: var(--border-strong);
  }

  .btn--ghost:hover:not(:disabled) { background: color-mix(in srgb, var(--text) 7%, transparent); }

  .btn--small { min-height: 36px; padding: 6px 14px; font-size: 0.92rem; border-radius: 10px; }
  .btn--block { width: 100%; }

  .button_to { display: inline-flex; margin: 0; }
  .button_to:has(> .btn--block) { display: flex; width: 100%; }

  .actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 18px;
  }

  .form > :first-child { margin-top: 0; }

  .field {
    display: grid;
    gap: 6px;
    margin: 0 0 16px;
    padding: 0;
    border: 0;
  }

  .field > label,
  .field > legend { font-weight: 700; }
  .field > legend { margin-bottom: 8px; padding: 0; }

  .field input:not([type="checkbox"], [type="radio"], [type="hidden"]),
  .field select,
  .field textarea {
    width: 100%;
    min-height: 48px;
    padding: 10px 14px;
    border: 1.5px solid var(--border-strong);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    font-size: 1.0625rem;
  }

  .field input:focus-visible,
  .field select:focus-visible,
  .field textarea:focus-visible { outline-offset: 1px; border-color: var(--focus); }

  .field--inline {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr);
    align-items: center;
    margin-bottom: 10px;
  }

  .field--inline > label { font-weight: 600; }

  .field__hint { color: var(--text-muted); font-size: 0.92rem; }

  .form__errors {
    margin-bottom: 16px;
    padding: 12px 16px;
    border-left: 5px solid var(--danger);
    border-radius: var(--radius-sm);
    background: var(--danger-surface);
  }

  .form__errors ul { margin: 6px 0 0; padding-left: 20px; }

  .form__links {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px 16px;
    margin-top: 16px;
    font-size: 0.95rem;
  }

  .form__links a { display: inline-block; padding-block: 4px; }

  .invite-link code {
    display: block;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: var(--surface-sunk);
    font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
    font-size: 0.95rem;
    word-break: break-all;
    user-select: all;
  }
}

@media (max-width: 639.98px) {
  @layer components {
    .topbar__who,
    .topbar__turns-text { display: none; }
    .topbar__turns { padding-right: 4px; }
  }
}

@media (max-width: 479.98px) {
  @layer components {
    /* Too narrow for the full wordmark and the holiday sentence; both stay readable for screen readers. */
    .topbar__name,
    .topbar__away-prefix {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip-path: inset(50%);
      white-space: nowrap;
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .flash, .flash.is-leaving { animation: none; }
  .btn { transition: none; }
}
