/* Design tokens */
:root {
  --color-bg: #f6f1ea;
  --color-surface: #fffdf9;
  --color-surface-2: #f9f5ef;
  --color-ink: #0f2f2f;
  --color-muted: #5c6b6b;
  --color-accent: #0d9488;
  --color-accent-strong: #0b7a70;
  --color-accent-soft: #e3f3f0;
  --color-accent-2: #e85d4c;
  --color-accent-2-soft: #fdecea;
  --color-warn: #a35a00;
  --color-warn-soft: #fbf0df;
  --color-border: #e2d8cc;
  --color-border-strong: #cfc3b4;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --shadow-card: 0 1px 2px rgb(15 47 47 / 0.04), 0 4px 16px rgb(15 47 47 / 0.05);
  --focus-ring: 0 0 0 3px rgb(13 148 136 / 0.28);
  --tap: 44px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --font:
    system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Noto Sans CJK JP",
    "Yu Gothic UI", sans-serif;
}

* {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  background: var(--color-bg);
  color: var(--color-ink);
}
[hidden] {
  display: none !important;
}
a {
  color: var(--color-accent-strong);
}
h1,
h2,
h3 {
  line-height: 1.35;
  letter-spacing: 0.01em;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgb(255 253 249 / 0.92);
  backdrop-filter: saturate(1.2) blur(8px);
  border-bottom: 1px solid var(--color-border);
}
.topbar-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: var(--space-2) var(--space-4);
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-ink);
  text-decoration: none;
  white-space: nowrap;
}
.brand img {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}
.brand-tag {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: var(--radius-pill);
  background: var(--color-ink);
  color: var(--color-surface);
}
.user-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  font-size: 0.85rem;
  color: var(--color-muted);
}
.user-bar .user-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Page */
main {
  max-width: 760px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-6);
}
.page-intro {
  margin: 0 0 var(--space-5);
}
.page-intro h2 {
  margin: 0 0 var(--space-1);
  font-size: 1.35rem;
}
.page-intro p {
  margin: 0;
  color: var(--color-muted);
}

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}
.card-head {
  margin-bottom: var(--space-4);
}
.card-head h2,
.card > h2 {
  margin: 0;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.card-head p {
  margin: var(--space-1) 0 0;
  color: var(--color-muted);
  font-size: 0.88rem;
}
.step {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-pill);
  background: var(--color-accent-soft);
  color: var(--color-accent-strong);
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}
.card.subtle {
  background: var(--color-surface-2);
  box-shadow: none;
}

/* Forms */
fieldset {
  border: 0;
  padding: 0;
  margin: 0 0 var(--space-5);
  min-width: 0;
}
legend {
  padding: 0;
  margin-bottom: var(--space-3);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--color-muted);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
fieldset.optional {
  padding: var(--space-4);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
}
fieldset.optional legend {
  float: left;
  width: 100%;
}
fieldset.optional legend + * {
  clear: both;
}
.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3) var(--space-4);
}
.field-grid .span-2 {
  grid-column: 1 / -1;
}
label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
}
.field-grid label {
  margin: 0;
}
label .req {
  color: var(--color-accent-2);
  margin-left: 2px;
}
input:not([type="checkbox"]),
textarea,
select {
  display: block;
  width: 100%;
  margin-top: 6px;
  min-height: var(--tap);
  padding: 10px 12px;
  font: inherit;
  font-weight: 400;
  color: var(--color-ink);
  background: #fff;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
textarea {
  line-height: 1.6;
  resize: vertical;
}
input::placeholder,
textarea::placeholder {
  color: #9aa5a5;
}
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--focus-ring);
}
select:disabled,
textarea[readonly] {
  background: var(--color-surface-2);
}
label.check {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  font-weight: 600;
  cursor: pointer;
}
label.check input {
  width: 18px;
  height: 18px;
  margin: 3px 0 0;
  accent-color: var(--color-accent);
  flex-shrink: 0;
}
label.check .hint {
  display: block;
  font-weight: 400;
  margin-top: 2px;
}

/* Buttons */
button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: 0 18px;
  border: 1px solid var(--color-accent);
  background: var(--color-accent);
  color: #fff;
  border-radius: var(--radius-pill);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s;
}
button:hover,
.button:hover {
  background: var(--color-accent-strong);
  border-color: var(--color-accent-strong);
}
button:focus-visible,
.button:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
button.secondary,
.button.secondary {
  background: transparent;
  color: var(--color-accent-strong);
  border-color: var(--color-border-strong);
}
button.secondary:hover,
.button.secondary:hover {
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
}
button.danger {
  color: var(--color-accent-2);
  border-color: rgb(232 93 76 / 0.45);
}
button.danger:hover {
  background: var(--color-accent-2-soft);
  border-color: var(--color-accent-2);
  color: #c0412f;
}
button.small {
  min-height: 36px;
  padding: 0 14px;
  font-size: 0.85rem;
}
button.large {
  min-height: 48px;
  padding: 0 28px;
  font-size: 1rem;
}
button:disabled,
button:disabled:hover {
  opacity: 0.45;
  cursor: not-allowed;
  background: var(--color-accent);
  border-color: var(--color-accent);
}
button.secondary:disabled,
button.secondary:disabled:hover {
  background: transparent;
  border-color: var(--color-border-strong);
}

.row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  margin-top: var(--space-3);
}
.row.wrap {
  flex-wrap: wrap;
}
.row input {
  flex: 1;
  margin-top: 0;
  min-width: 0;
}
.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

/* Text helpers */
.hint {
  color: var(--color-muted);
  font-size: 0.85rem;
  font-weight: 400;
  margin: var(--space-2) 0 0;
}
.hint:empty {
  display: none;
}
#tonamel-status {
  white-space: pre-line;
}
.error {
  color: #c0412f;
}
.warn {
  color: var(--color-warn);
}
p.hint.error,
p.hint.warn {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
}
p.hint.error {
  background: var(--color-accent-2-soft);
}
p.hint.warn {
  background: var(--color-warn-soft);
}

/* Template editor & preview */
.editor {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin: var(--space-4) 0;
  background: var(--color-surface-2);
}
.editor h3 {
  font-size: 0.95rem;
  margin: 0 0 var(--space-3);
}
.editor label + label {
  margin-top: var(--space-3);
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: var(--space-2);
}
button.chip {
  min-height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  border-color: var(--color-border-strong);
  background: var(--color-surface);
  color: var(--color-ink);
  font-size: 0.8rem;
  font-weight: 500;
}
button.chip:hover {
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
}
.preview-label {
  display: block;
  margin: var(--space-4) 0 0;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--color-muted);
}
#template-preview {
  background: var(--color-surface-2);
  border-style: dashed;
}

/* Chips / badges */
.badge,
.status-chip {
  display: inline-flex;
  align-items: center;
  padding: 1px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  background: #efe8de;
  color: var(--color-muted);
}
.badge.warn,
.status-chip.warn {
  background: var(--color-warn-soft);
  color: var(--color-warn);
}
.status-chip.published {
  background: var(--color-accent-soft);
  color: var(--color-accent-strong);
}
.status-chip.draft {
  background: #efe8de;
  color: var(--color-muted);
}
.req-chip {
  background: var(--color-accent-2-soft);
  color: #c0412f;
  letter-spacing: 0;
}
.opt-chip {
  letter-spacing: 0;
}

/* Tabs (segmented) */
.tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  margin-bottom: var(--space-3);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  max-width: 100%;
}
.tabs button {
  min-height: 38px;
  padding: 0 16px;
  border: 0;
  font-size: 0.88rem;
}
.tabs button[aria-selected="false"] {
  background: transparent;
  color: var(--color-muted);
}
.tabs button[aria-selected="false"]:hover {
  color: var(--color-ink);
  background: var(--color-surface);
}
.tabs button[aria-selected="true"] {
  background: var(--color-ink);
  color: var(--color-surface);
}

/* Lists */
.list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.list li {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-border);
}
.list li:first-child {
  border-top: 0;
}
.list li.empty {
  display: block;
  padding: var(--space-5) var(--space-3);
  text-align: center;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-muted);
  font-size: 0.9rem;
}
.list .meta {
  flex: 1 1 220px;
  min-width: 0;
  overflow-wrap: anywhere;
}
.list .meta strong {
  display: block;
  font-size: 0.95rem;
}
.list .meta .hint {
  display: block;
  margin: 2px 0 0;
}
.list .chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
}
.list .actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  flex-shrink: 0;
}
.list li > button {
  flex-shrink: 0;
}
#admin-event-pagination:not(:empty) {
  margin-top: var(--space-3);
  text-align: center;
}

/* Gate */
.gate {
  text-align: center;
  padding: var(--space-6) var(--space-5);
}
.gate-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-3);
  display: block;
}
.gate h2,
.gate h3 {
  justify-content: center;
  margin: 0 0 var(--space-2);
  font-size: 1.25rem;
}
.gate p {
  margin: 0 auto var(--space-2);
  max-width: 34em;
  color: var(--color-muted);
}
.gate .gate-actions + .hint {
  margin-top: var(--space-3);
}
.gate .gate-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-4);
}
.gate .gate-actions button {
  min-width: 240px;
}
.steps {
  list-style: none;
  display: flex;
  justify-content: center;
  gap: var(--space-2);
  padding: 0;
  margin: var(--space-5) 0 0;
  flex-wrap: wrap;
}
.steps li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px 4px 4px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  font-size: 0.8rem;
  color: var(--color-muted);
}
.steps li.done .step {
  background: var(--color-accent);
  color: #fff;
}
.steps li.current {
  border-color: var(--color-accent);
  color: var(--color-ink);
  font-weight: 600;
}
.gate .list {
  margin-top: var(--space-3);
  text-align: left;
}
.gate .gate-events {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
  text-align: left;
}
.gate .gate-events h3 {
  font-size: 0.95rem;
}
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
}

/* Boot loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  color: var(--color-muted);
}
.loading p {
  margin: 0;
}
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
  }
}

/* Mobile */
@media (max-width: 560px) {
  body {
    font-size: 15px;
  }
  main {
    padding: var(--space-4) var(--space-3) var(--space-6);
  }
  .card {
    padding: var(--space-4);
  }
  .gate {
    padding: var(--space-5) var(--space-4);
  }
  .field-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  fieldset.optional {
    padding: var(--space-3);
  }
  .brand-name-long {
    display: none;
  }
  .row.stack-sm {
    flex-direction: column;
    align-items: stretch;
  }
  .form-actions > button,
  .gate .gate-actions button {
    width: 100%;
    min-width: 0;
  }
  .list li {
    align-items: stretch;
  }
  .list .actions {
    width: 100%;
  }
  .list .actions button {
    flex: 1 1 auto;
  }
  .tabs {
    display: flex;
  }
  .tabs button {
    flex: 1;
    padding: 0 8px;
  }
}
.gate-form {
  text-align: left;
  max-width: 380px;
  margin: var(--space-5) auto 0;
}
.gate-form .form-actions {
  border-top: 0;
  padding-top: 0;
  margin-top: var(--space-4);
}
.gate-form .form-actions button {
  width: 100%;
}
