/* Design v2 (spec.md). Tokens and layout follow the CD mocks. */
:root {
  --bg-fallback: #b00afc;
  --surface: #ffffff;
  --ink: #0d0b3a;
  --ink-muted: #514f71;
  --accent: #110afc;
  --btn: #fcee09;
  --quote: #b00afc;
  --note: #c0c0cc;
  --btn2-hover: rgba(13, 11, 58, 0.2);
  --btn1-active: #dfd30f;
  --btn1-disabled-bg: #c854fd;
  --btn1-disabled-fg: #f3daff;
  --btn2-disabled: #df9dfe;
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 32px;
  --sp-8: 48px;
  --sp-9: 64px;
  --qmark-width: 56px;
  /* Provisional until the CD decides. Used by .footer-follow-label on all widths. */
  /* Footer "Follows" type. CD 2026-11-15 19:25. Change here if the CD tweaks it. */
  --footer-follows-size: 16px;
  --footer-follows-weight: 700;
  --footer-follows-tracking: 0.08em;
  --footer-follows-leading: 1.2;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans",
    "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", Meiryo,
    "Noto Sans JP", "Noto Sans CJK JP", sans-serif;
}

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

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  background-color: #B00AFC;
  overflow-x: clip;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--surface);
  background-color: #B00AFC;
  overflow-x: clip;
}

/* Mesh lives in .rhs-mesh (motion.css), clipped by .rhs-mesh-parent. */
.page {
  min-height: 100dvh;
  background-color: #B00AFC;
  position: relative;
}

/* Content above the fixed mesh (z-index: -1). */
.page > *:not(.rhs-mesh):not(.rhs-mesh-parent):not(.skip) {
  position: relative;
  z-index: 1;
}

.skip {
  position: absolute;
  left: var(--sp-3);
  top: -3.5rem;
  z-index: 20;
  padding: var(--sp-2) 0.85rem;
  background: var(--btn);
  color: var(--ink);
  text-decoration: none;
  border-radius: var(--sp-2);
  font-weight: 700;
}

.skip:focus {
  top: var(--sp-3);
}

.skip:focus-visible,
.btn:focus-visible,
.logo:focus-visible,
.source-link:focus-visible,
.footer-follow-link:focus-visible {
  box-shadow: 0 0 0 2px var(--ink);
  outline: 3px solid var(--surface);
  outline-offset: 2px;
}

.wrap {
  width: min(1200px, calc(100% - 40px));
  margin-inline: auto;
}

.masthead {
  padding: 16px 0 0;
}

.masthead .wrap {
  line-height: 0;
}

.logo {
  display: inline-block;
  width: min(200px, 70vw);
  line-height: 0;
  border-radius: var(--sp-2);
}

.logo svg {
  display: block;
  width: 100%;
  height: auto;
}

/* ロゴの★きらりん（位置は動かさない。拡大・回転・光だけ） */
.logo-star {
  transform-box: fill-box;
  transform-origin: center;
}

.logo-star.is-kirarin {
  animation: rhs-kirarin 700ms ease-out both;
}

@keyframes rhs-kirarin {
  0% {
    transform: scale(1) rotate(0deg);
    filter: drop-shadow(0 0 4px rgba(252, 238, 9, 0));
  }
  35% {
    transform: scale(1.25) rotate(18deg);
    filter: drop-shadow(0 0 4px rgba(252, 238, 9, 0.9));
  }
  70% {
    transform: scale(0.95) rotate(0deg);
    filter: drop-shadow(0 0 4px rgba(252, 238, 9, 0));
  }
  100% {
    transform: scale(1) rotate(0deg);
    filter: drop-shadow(0 0 4px rgba(252, 238, 9, 0));
  }
}

.layout {
  display: flex;
  flex-direction: column;
  padding: 18px 0 24px;
  flex: 1 1 auto;
}

.intro {
  margin-bottom: 20px;
}

h1 {
  margin: 0 0 18px;
  color: var(--surface);
  font-size: 38px;
  line-height: 1; /* 38px; second line offset below yields 1.3 (50px) like the mock */
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* Each title line is a static span and must not wrap mid-word (CD: always two lines). */
.title-line,
.title-break {
  display: block;
  white-space: nowrap;
}

.title-break {
  margin-top: 12px; /* 38 + 12 = 50 */
}

.lead {
  display: block;
  margin: 0;
  color: var(--surface);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
  word-break: keep-all;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.stack {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
}

.card {
  position: relative;
  margin: 0;
  padding: 20px;
  background: var(--surface);
  color: var(--ink);
  border-radius: 24px;
}

.status[hidden] {
  display: none !important;
}

.quote-slot {
  min-width: 0;
  max-width: 100%;
}

.qmark {
  display: none;
  position: absolute;
  top: 36px;
  right: 40px;
  width: var(--qmark-width, 56px);
  height: 42px;
  color: var(--quote);
  pointer-events: none;
}

.qmark svg {
  display: block;
  width: 100%;
  height: 100%;
}

.quote-text {
  margin: 0 0 12px;
  font-size: 22px;
  line-height: 1.5;
  font-weight: 700;
  color: var(--ink);
  line-break: strict;
  overflow-wrap: anywhere;
  word-break: break-word;
  word-break: auto-phrase;
  text-wrap: pretty;
}

.rule {
  width: 32px;
  height: 4px;
  margin: 0 0 10px;
  border: 0;
  border-radius: 2px;
  background: var(--accent);
}

.quote-person {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 14.5px;
  line-height: 1.5;
  font-weight: 700;
}

.quote-source {
  margin: 0;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.6;
  color: var(--ink-muted);
  line-break: strict;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.source-link {
  position: relative;
  display: inline-block;
  color: var(--ink-muted);
  text-decoration: underline;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
  vertical-align: baseline;
}

/* タップ領域だけ広げる（フォーカス枠は文字に沿わせる） */
.source-link::before {
  content: "";
  position: absolute;
  inset: -13px 0;
}

.source-newtab {
  display: inline;
  margin-inline-start: 0.15em;
  font-size: 0.85em;
  pointer-events: none;
}

.source-link:hover,
.source-link:focus-visible {
  color: var(--accent);
}

.translation-note {
  display: block;
  margin-top: 4px;
}

.companion {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 24px;
  min-width: 0;
  max-width: 100%;
}

.follow-slot {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
}

.follow-slot:empty {
  flex: 0 0 0;
  width: 0;
  min-width: 0;
  overflow: hidden;
}

.character {
  flex: 0 0 auto;
  width: 72px;
  height: 72px;
}

.character svg {
  display: block;
  width: 100%;
  height: 100%;
}

.bubble {
  position: relative;
  margin: 0;
  padding: 14px 16px;
  background: var(--surface);
  color: var(--ink);
  border-radius: 18px;
}


.bubble::after {
  content: "";
  position: absolute;
  left: -10px;
  top: 50%;
  margin-top: -10px;
  border-style: solid;
  border-width: 10px 13px 10px 0;
  border-color: transparent var(--surface) transparent transparent;
}

.bubble-label {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.5;
}

.bubble-text {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.55;
  color: var(--ink);
  overflow-wrap: anywhere;
  word-break: break-word;
  word-break: auto-phrase;
  text-wrap: pretty;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 32px;
  min-width: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-sizing: border-box;
  height: auto;
  min-height: 56px;
  min-width: 0;
  max-width: 100%;
  padding: 10px 16px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.2;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  border: 2px solid transparent;
  appearance: none;
  width: 100%;
}

.btn svg {
  width: 1.25rem;
  height: 1.25rem;
  flex: 0 0 auto;
}

.btn-primary {
  background: var(--btn);
  color: var(--ink);
  border-color: var(--btn);
}

.btn-primary:hover:not([aria-disabled="true"]) {
  background: var(--surface);
  border-color: var(--surface);
  color: var(--ink);
}

.btn-primary:active:not([aria-disabled="true"]) {
  background: var(--btn1-active);
  border-color: var(--btn1-active);
  color: var(--ink);
  transform: scale(0.97);
}

.btn-primary[aria-disabled="true"],
.btn-primary.is-loading {
  cursor: not-allowed;
}

.btn-primary[aria-disabled="true"]:not(.is-loading) {
  background: var(--btn1-disabled-bg);
  border-color: var(--btn1-disabled-bg);
  color: var(--btn1-disabled-fg);
}

.btn-secondary {
  background: transparent;
  color: var(--surface);
  border-color: var(--surface);
}

.btn-secondary:hover:not(.is-disabled) {
  background: var(--btn2-hover);
}

.btn-secondary:active:not(.is-disabled) {
  background: var(--surface);
  border-color: var(--surface);
  color: var(--ink);
  transform: scale(0.97);
}

.btn-secondary.is-disabled {
  pointer-events: none;
  color: var(--btn2-disabled);
  border-color: var(--btn2-disabled);
  cursor: not-allowed;
}

.icon-spinner {
  display: none;
}

.btn.is-loading .icon-refresh {
  display: none;
}

.btn.is-loading .icon-spinner {
  display: block;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.status {
  margin: 0 0 16px;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
}

.status.is-error {
  outline: 2px solid var(--btn);
}

.footer {
  margin-top: auto;
  background: var(--ink);
  color: var(--surface);
  text-align: center;
  padding: 40px 16px calc(40px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
}

.footer-inner {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.footer p {
  margin: 0;
  text-align: center;
}

.footer-main {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.footer-note {
  margin: 0 auto;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.6;
  color: var(--surface);
  max-width: 36rem;
  width: 100%;
  word-break: keep-all;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.footer-grokbot,
.footer-note-end {
  white-space: nowrap;
}

/* auto-phrase in current Chrome breaks after 「の」, not after 「、」.
   keep-all + text-wrap: balance is what produces the intended comma break. */

.footer-follow {
  margin: 32px auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.footer-follow-label {
  font-size: var(--footer-follows-size);
  font-weight: var(--footer-follows-weight);
  line-height: var(--footer-follows-leading);
  letter-spacing: var(--footer-follows-tracking);
  color: var(--surface);
  white-space: nowrap;
}

.footer-follow-links {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 12px; /* Follows → icon row; CD 19:25 */
}

.footer-follow-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: var(--surface);
  border-radius: 12px;
  text-decoration: none;
}

.footer-follow-link:hover {
  background: rgba(255, 255, 255, 0.1);
}

.footer-icon-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
}

/* White 32x32 rounded square. rx matches official note app/icon.svg
   (viewBox 493, rect rx 104) scaled to 32px: 104/493 * 32 ≈ 6.75px. */
.footer-x-badge {
  background: #ffffff;
  border-radius: calc(104 / 493 * 32px);
  overflow: hidden;
}

/* Official X path, fill black. Larger side of the viewBox (1227) is 16px.
   Clear space inside the 32px badge is 8px on each side (half the mark). */
.footer-x-icon {
  display: block;
  height: 16px;
  width: auto;
  aspect-ratio: 1200 / 1227;
}

.footer-note-icon {
  display: block;
  width: 32px;
  height: 32px;
}

.footer .footer-credit {
  margin: 24px auto 0;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.6;
  letter-spacing: 0.02em;
  color: var(--surface);
  width: 100%;
  overflow-wrap: anywhere;
}

/* Short mobile screens: move the bubble below the buttons (DOM order unchanged). */
/* スマホ（幅599px以下・高さは問わない）：カード → ボタン → 吹き出し（HTML順はそのまま）
   CD 追記の詰め。PC（1024px〜）の値は変えない。 */
@media (max-width: 599px) {
  .masthead {
    padding-top: 12px;
  }

  .layout {
    padding-top: 16px; /* ロゴ → タイトル */
  }

  h1 {
    font-size: 34px;
    line-height: 1; /* 2行、行間 1.3 は次行の margin-top で取る */
  }

  .title-break {
    margin-top: 0.3em; /* 34 × 1.3 */
  }

  .intro {
    margin-bottom: 16px; /* リード → カード */
  }

  .card {
    padding: 18px;
  }

  .quote-text {
    font-size: 20px;
    line-height: 1.5;
    margin-bottom: 10px; /* 引用 → ルール */
  }

  .translation-note {
    font-size: 12px;
    line-height: 1.6;
  }

  .quote-slot {
    order: 0;
  }

  .actions {
    order: 1;
    margin-top: 20px; /* カード → ボタン */
    gap: 10px; /* ボタン同士 */
  }

  .btn {
    min-height: 52px; /* ≥44px */
  }

  .companion {
    order: 2;
    margin-top: 24px; /* ボタン → 吹き出し */
  }
}

/* Tablet: still one column, narrower centered column */
@media (min-width: 768px) {
  .footer {
    padding: 32px 0 calc(32px + env(safe-area-inset-bottom, 0px));
  }

  .footer-inner {
    width: min(560px, calc(100% - 40px));
    margin-inline: auto;
    align-items: stretch;
  }

  .footer-main {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 48px;
    align-items: center;
    width: 100%;
  }

  .footer-follow {
    grid-column: 1;
    grid-row: 1;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 16px; /* Follows → X icon */
    margin: 0;
    width: auto;
  }

  .footer-follow-links {
    margin-top: 0;
    justify-content: flex-start;
    gap: 12px;
  }

  .footer .footer-note {
    grid-column: 2;
    grid-row: 1;
    margin: 0 0 0 auto;
    width: auto;
    max-width: 34em;
    text-align: right;
    text-wrap: balance;
  }

  /* 24px below the top row, then a 1px line at content-column width, then 20px to ©. */
  .footer-main::after {
    content: "";
    display: block;
    grid-column: 1 / -1;
    width: 100%;
    height: 1px;
    margin: 24px 0 0;
    background: rgba(255, 255, 255, 0.16);
  }

  .footer .footer-credit {
    margin-top: 20px;
    text-align: center;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .wrap {
    width: min(560px, calc(100% - 40px));
  }
}

/* PC */
@media (min-width: 1024px) and (max-width: 1199px) {
  /* One column: header, title, lead, card, bubble, buttons, footer
     all sit in a 640px centred column. Footer 2-col (from 768) stays inside it. */
  .wrap,
  .footer-inner {
    width: 640px;
  }
}

@media (min-width: 1024px) {
  .masthead {
    padding-top: 40px;
  }

  .logo {
    width: 240px;
  }

  .layout {
    display: flex;
    flex-direction: column;
    padding: 32px 0 48px;
  }

  .intro {
    margin-bottom: 32px;
  }

  h1 {
    font-size: clamp(48px, 4.4vw, 64px);
    line-height: 1;
    margin-bottom: 24px;
  }

  .title-break {
    margin-top: 20px; /* 64 + 20 = 84, ≈1.3 at the 64px cap */
  }

  .lead {
    font-size: 20px;
    line-height: 1.6;
  }

  .card {
    padding: 48px;
  }

  .qmark {
    display: block;
  }

  .quote-text {
    font-size: 34px;
    line-height: 1.55;
    margin: 0 0 16px 0;
    padding-right: calc(var(--qmark-width, 56px) + 24px);
  }

  .quote-person {
    font-size: 18px;
  }

  .quote-source {
    font-size: 16px;
  }

  .companion {
    margin-top: 24px;
  }

  .character {
    width: 80px;
    height: 80px;
  }

  .bubble {
    padding: 16px 18px;
  }

  .bubble-label {
    font-size: 13px;
  }

  .bubble-text {
    font-size: 16px;
    line-height: 1.6;
  }

  .actions {
    margin-top: 32px;
    flex-direction: row;
    gap: 24px;
  }

  .btn {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    min-height: 64px;
    max-width: none;
    font-size: 20px;
  }

  /* Footer layout is defined from 768px. Do not reset it to a stacked centre here. */
}

/* Two-column hero from 1200px. Card is 560px (never smaller).
   Wrap is min(1200px, 100% - 80px) so at 1200 the left column is 480px
   with an 80px gap — enough for the ~417px lead and the 6-character title
   (a 240px side inset would make wrap 960 and the lead would not fit,
   even with gap 0). Gap stays 80px; reduce it only if a width fails the fit. */
@media (min-width: 1200px) {
  .wrap,
  .footer-inner {
    width: min(1200px, calc(100% - 80px));
  }

  .layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 560px;
    column-gap: 80px;
    align-items: center;
    padding: 32px 0 48px;
  }

  .status {
    grid-column: 1 / -1;
  }

  .intro {
    align-self: center;
    margin-bottom: 0;
  }

  .stack {
    min-width: 0;
    width: 560px;
    max-width: 560px;
    align-self: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  /* Do not zero all animation: motion.css keeps a 200ms fade on .is-entering. */
  .btn,
  .btn:active:not([aria-disabled="true"]) {
    transition: none;
    transform: none;
  }

  .icon-spinner,
  .btn.is-loading .icon-spinner {
    animation: none;
  }

  .logo-star.is-kirarin {
    animation: none;
  }
}

/* Browser translation wraps text in <font>; keep wrapping and alignment. */
font {
  vertical-align: inherit;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Wand / star pivots from character_anim.svg, moved here so we do not use inline style (CSP style-src 'self'). Amplitudes unchanged. */
.rhs-chara__wand { transform-origin: 408px 258px; }
.rhs-chara__star { transform-origin: 462px 150px; }
.rhs-chara__sparkle--1 { transform-origin: 528px 92px; }
.rhs-chara__sparkle--2 { transform-origin: 388px 112px; }

/* Stop quote enter animation too when the tab is hidden (spec: stop ALL motion). */
.is-tab-hidden .is-entering,
.is-tab-hidden .logo-star.is-kirarin {
  animation-play-state: paused !important;
}
