/* ============================================================
   CSS ARCHITECTURE — LAYERED, REGRESSION-SAFE

   LAYER ORDER (DO NOT REORDER):
   1. reset        – browser / box model
   2. base         – typography, layout, containers
   3. components   – chips, buttons, UI structure ONLY
   4. variants     – semantic chip categories (COLOR ONLY)
   5. themes       – light/dark overrides (COLOR ONLY)
   ============================================================ */

/* ============================================================
   1. RESET
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }

/* ============================================================
   2. BASE
   ============================================================ */
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
               Roboto, Helvetica, Arial, sans-serif;
  background-color: #f5f5f7;
  color: #1d1d1f;
  --accent-color: #1d1d1f;
  --accent-text: #ffffff;
  --accent-shadow: rgba(0, 0, 0, 0.45);
  --focus-ring: #1d1d1f;
  min-height: 100vh;
  min-height: 100dvh;
}

body.modal-open {
  overflow: hidden;
}

body[data-theme="dark"] {
  background-color: #1c1c1e;
  color: #f5f5f7;
  --accent-color: #f5f5f7;
  --accent-text: #1d1d1f;
  --accent-shadow: rgba(0, 0, 0, 0.65);
  --focus-ring: #f5f5f7;
}

.container {
  max-width: 500px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
  background-color: #ffffff;
  min-height: 100vh;
  min-height: 100dvh;
}

body[data-theme="dark"] .container {
  background-color: #2c2c2e;
}

.top-note {
  font-size: 15px;
  margin: 0 0 16px;
  font-weight: 500;
}

.header {
  position: relative;
  text-align: center;
  margin-bottom: 28px;
}

.header h1 {
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 8px;
  letter-spacing: -0.5px;
}

.header p {
  font-size: 15px;
  color: #6e6e73;
  margin: 0;
}

.header-intro {
  margin-bottom: 12px;
  line-height: 1.45;
}

.header-note {
  font-size: 14px;
  opacity: 0.8;
  font-style: italic;
  line-height: 1.4;
}

.theme-toggle {
  position: absolute;
  top: -6px;
  right: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid #c7c7cc;
  background: #f5f5f7;
  color: #3a3a3c;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.theme-toggle:hover {
  background: #ebebf0;
  border-color: #b7b7be;
}

.theme-toggle__icon {
  width: 16px;
  height: 16px;
  display: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

body[data-theme="light"] .theme-toggle__icon--sun {
  display: block;
}

body[data-theme="dark"] .theme-toggle__icon--moon {
  display: block;
}

.section {
  margin-bottom: 24px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #6e6e73;
  margin: 0 0 12px;
  padding-left: 4px;
}

/* ============================================================
   3. COMPONENTS (STRUCTURE ONLY — NON-NEGOTIABLE)
   ============================================================ */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  min-height: 44px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 22px;
  border: 1.5px solid #e5e5ea;
  background-color: #f5f5f7;
  color: #1d1d1f;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
  touch-action: manipulation;
}

.chip:hover {
  background-color: #ebebed;
  border-color: #d1d1d6;
}

.chip:active {
  transform: scale(0.96);
}

.chip[aria-pressed="true"] {
  transform: scale(1.02);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

/* ICON HARD CLAMP — NEVER OVERRIDE */
.chip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.chip-icon svg {
  width: 18px;
  height: 18px;
  max-width: 18px;
  max-height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.chip-label { line-height: 1.2; }

/* ============================================================
   ALIGNED STATUS (SIZE-CLAMPED)
   ============================================================ */

.aligned-status {
  display: none;
  align-items: center;
  gap: 10px;
  margin: 16px 0 24px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid #d1fae5;
  background: #ecfdf5;
  color: #065f46;
  font-size: 14px;
  font-weight: 500;
}

.aligned-status-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
}

.aligned-status-icon svg {
  width: 20px;
  height: 20px;
  max-width: 20px;
  max-height: 20px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* Action bar + buttons (structure only) */
.action-bar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid #e5e5ea;
}

.counter {
  text-align: center;
  font-size: 14px;
  color: #6e6e73;
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
}

.action-hint {
  margin: 2px 0 0;
  text-align: center;
  font-size: 13px;
  color: #6e6e73;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 16px 26px;
  min-height: 48px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 24px;
  border: 2px solid #8e8e93;
  background: #f2f2f7;
  color: #1d1d1f;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.action-btn:hover {
  background-color: #e5e5ea;
}

.action-btn.primary {
  background-color: var(--accent-color);
  border-color: var(--accent-color);
  color: var(--accent-text);
}

.action-btn.secondary {
  background: #ffffff;
  color: #1d1d1f;
  border-color: #c7c7cc;
}

.action-btn--utility {
  min-height: 44px;
  padding: 12px 20px;
  font-size: 15px;
  margin-top: 6px;
}

.chip:focus-visible,
.action-btn:focus-visible,
#theme-toggle:focus-visible,
#preview-btn:focus-visible,
#clear-btn:focus-visible,
.followup-modal__button:focus-visible,
.preview-modal__button:focus-visible,
.preview-modal__close:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(100px + var(--toast-offset, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background-color: #1d1d1f;
  color: #ffffff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
  z-index: 1000;
}

.toast.visible {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* Follow-up modal (disruptive) */
.followup-modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 8, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 3000;
}

.followup-modal.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.followup-modal__content {
  width: min(520px, 100%);
  background: #ffffff;
  color: #111111;
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(0, 0, 0, 0.08);
}

.followup-modal__title {
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--accent-color);
  margin: 0 0 12px;
}

.followup-modal__text {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 20px;
  line-height: 1.3;
}

.followup-modal__actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.followup-modal__actions.single {
  align-items: center;
}

.followup-modal__button {
  padding: 14px 18px;
  border-radius: 14px;
  border: 2px solid #111111;
  background: #111111;
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.followup-modal__button.secondary {
  background: transparent;
  color: #111111;
}

body[data-theme="dark"] .followup-modal__content {
  background: #1d1d1f;
  color: #f5f5f7;
  border-color: rgba(255, 255, 255, 0.12);
}

body[data-theme="dark"] .followup-modal__button.secondary {
  color: #f5f5f7;
  border-color: #f5f5f7;
}

/* ============================================================
   PREVIEW MODAL
   ============================================================ */
.preview-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
  padding: 24px 16px;
  z-index: 3500;
}

.preview-modal.is-visible {
  opacity: 1;
  visibility: visible;
}

.preview-modal__content {
  position: relative;
  width: min(520px, 100%);
  background: #ffffff;
  color: inherit;
  border-radius: 20px;
  padding: 20px 18px 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(0, 0, 0, 0.08);
}

.preview-modal__close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid #d1d1d6;
  background: #ffffff;
  color: #1d1d1f;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.preview-modal__title {
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--accent-color);
  margin: 0 0 12px;
}

.preview-modal__body {
  margin: 0 0 16px;
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid #e5e5ea;
  background: #f5f5f7;
  font-size: 14px;
  line-height: 1.45;
  font-family: inherit;
  white-space: pre-wrap;
  max-height: 52vh;
  overflow: auto;
}

.preview-modal__actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.preview-modal__button {
  padding: 12px 16px;
  border-radius: 14px;
  border: 2px solid #111111;
  background: #111111;
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.preview-modal__button.secondary {
  background: transparent;
  color: #111111;
}

body[data-theme="dark"] .preview-modal__content {
  background: #1d1d1f;
  border-color: rgba(255, 255, 255, 0.12);
}

body[data-theme="dark"] .preview-modal__body {
  background: #2c2c2e;
  border-color: #38383a;
}

body[data-theme="dark"] .preview-modal__close {
  background: #2c2c2e;
  color: #f5f5f7;
  border-color: #636366;
}

body[data-theme="dark"] .preview-modal__button.secondary {
  color: #f5f5f7;
  border-color: #f5f5f7;
}

.heart-flash {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 5, 8, 0.95);
  font-size: min(50vw, 220px);
  opacity: 0;
  pointer-events: none;
  z-index: 4000;
}

.heart-flash.is-visible {
  animation: heartFlash 0.8s ease-out;
}

body.reduce-motion .heart-flash,
body.reduce-motion .combat-floater {
  display: none;
}

@keyframes heartFlash {
  0% { opacity: 0; transform: scale(0.6); }
  30% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.15); }
}

/* Combat floater (retro game text) */
.combat-floater {
  position: fixed;
  left: var(--start-x);
  top: var(--start-y);
  transform: translate(-50%, -50%);
  z-index: 2000;
  pointer-events: none;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: var(--accent-color);
  text-transform: uppercase;
  text-shadow:
    0 2px 0 var(--accent-shadow),
    0 -2px 0 var(--accent-shadow),
    2px 0 0 var(--accent-shadow),
    -2px 0 0 var(--accent-shadow),
    0 0 8px var(--accent-shadow);
  animation: combatRise 8s cubic-bezier(0.2, 0.6, 0.2, 1) forwards;
}

.combat-floater__text {
  display: inline-block;
  animation: combatWiggle 1.4s ease-in-out infinite;
  transform: translateZ(0);
}

@keyframes combatRise {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--drift-x)), calc(-50% + var(--rise-y))) rotate(var(--rotate)) scale(1.1);
  }
}

@keyframes combatWiggle {
  0% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(var(--wiggle-x));
  }
  100% {
    transform: translateX(0);
  }
}

/* ============================================================
   4. VARIANTS (COLOR ONLY — SAFE TO EDIT)
   ============================================================ */
.chip--vibe {
  background-color: #f3e8ff;
  border-color: #d8b4fe;
  color: #6b21a8;
}
.chip--vibe[aria-pressed="true"] {
  background-color: #9333ea;
  border-color: #7e22ce;
  color: #ffffff;
  box-shadow: 0 0 0 2px rgba(88, 28, 135, 0.2);
}

.chip--physical {
  background-color: #e0f2fe;
  border-color: #bae6fd;
  color: #075985;
}
.chip--physical[aria-pressed="true"] {
  background-color: #0891b2;
  border-color: #0e7490;
  color: #ffffff;
  box-shadow: 0 0 0 2px rgba(8, 145, 178, 0.2);
}

.chip--safety {
  background-color: #dcfce7;
  border-color: #86efac;
  color: #166534;
}
.chip--safety[aria-pressed="true"] {
  background-color: #22c55e;
  border-color: #16a34a;
  color: #ffffff;
  box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.2);
}

.chip--situation {
  background-color: #eef2ff;
  border-color: #c7d2fe;
  color: #3730a3;
}
.chip--situation[aria-pressed="true"] {
  background-color: #6366f1;
  border-color: #4f46e5;
  color: #ffffff;
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2);
}

/* ============================================================
   5. THEMES (COLOR OVERRIDES ONLY)
   ============================================================ */
body[data-theme="dark"] .chip {
  background-color: #3a3a3c;
  color: #f5f5f7;
  border-color: #636366;
}

body[data-theme="dark"] .chip:hover {
  background-color: #48484a;
}

body[data-theme="dark"] .chip[aria-pressed="true"] {
  border-color: rgba(245, 245, 247, 0.7);
  box-shadow: 0 0 0 2px rgba(245, 245, 247, 0.18);
}

body[data-theme="dark"] .chip--vibe[aria-pressed="true"] {
  background-color: #9333ea;
  border-color: #7e22ce;
  color: #ffffff;
}

body[data-theme="dark"] .chip--physical[aria-pressed="true"] {
  background-color: #0891b2;
  border-color: #0e7490;
  color: #ffffff;
}

body[data-theme="dark"] .chip--safety[aria-pressed="true"] {
  background-color: #22c55e;
  border-color: #16a34a;
  color: #ffffff;
}

body[data-theme="dark"] .chip--situation[aria-pressed="true"] {
  background-color: #6366f1;
  border-color: #4f46e5;
  color: #ffffff;
}

body[data-theme="dark"] .action-bar {
  border-top-color: #38383a;
}

body[data-theme="dark"] .header h1 {
  color: #f5f5f7;
  -webkit-text-fill-color: #f5f5f7;
}

body[data-theme="dark"] .header p {
  color: #c7c7cc;
}

body[data-theme="dark"] .theme-toggle {
  background: #2c2c2e;
  color: #d1d1d6;
  border-color: #4a4a4c;
}

body[data-theme="dark"] .theme-toggle:hover {
  background: #353537;
  border-color: #5a5a5c;
}

body[data-theme="dark"] .top-note {
  color: #d1d1d6;
}

body[data-theme="dark"] .section-title,
body[data-theme="dark"] .counter,
body[data-theme="dark"] .footer-note {
  color: #c7c7cc;
}

body[data-theme="dark"] .action-hint {
  color: #c7c7cc;
}

body[data-theme="dark"] .action-btn {
  background-color: #3a3a3c;
  color: #f5f5f7;
  border-color: #636366;
}

body[data-theme="dark"] .action-btn:hover {
  background-color: #48484a;
}

body[data-theme="dark"] .action-btn.primary {
  background-color: var(--accent-color);
  border-color: var(--accent-color);
  color: var(--accent-text);
}

body[data-theme="dark"] .action-btn.secondary {
  background: #2c2c2e;
  color: #f5f5f7;
  border-color: #636366;
}

/* ============================================================
   FOOTER
   ============================================================ */
.footer {
  margin-top: 32px;
  text-align: center;
}

.footer-note {
  font-size: 14px;
  color: #6e6e73;
  margin: 0 0 8px;
  line-height: 1.4;
}

.footer-emphasis {
  margin-top: 8px;
  font-style: italic;
}

.footer-privacy {
  margin-top: 12px;
  font-weight: 500;
}

@media (prefers-reduced-motion: reduce) {
  .chip,
  .action-btn,
  #preview-btn,
  #clear-btn,
  .toast,
  .followup-modal,
  .preview-modal,
  .followup-modal__button,
  .preview-modal__button {
    transition: none;
  }

  .chip:active,
  .chip[aria-pressed="true"] {
    transform: none;
  }

  .heart-flash.is-visible,
  .combat-floater,
  .combat-floater__text {
    animation: none;
  }
}
