:root {
  color-scheme: light;
  --ink: #342b24;
  --muted: #766a5f;
  --cream: #fff8ec;
  --paper: #fffdf8;
  --line: #e9dccb;
  --shadow: 0 10px 26px rgba(88, 63, 36, 0.12);
  --safety: #df765f;
  --daily: #e4a451;
  --feeling: #639bc8;
  --main-red: #c9534c;
  --reason-yellow: #f1c85c;
  --request-green: #65a976;
  --neutral: #8278a8;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 5%, rgba(255, 219, 160, 0.28), transparent 24rem),
    var(--cream);
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; }
button:focus-visible { outline: 5px solid #315f99; outline-offset: 4px; }

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 68px;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(255, 248, 236, 0.94);
  border-bottom: 1px solid rgba(221, 203, 180, 0.82);
  backdrop-filter: blur(12px);
}

.brand,
.settings-hold {
  border: 0;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 8px;
  font-weight: 800;
  font-size: clamp(0.95rem, 2.4vw, 1.16rem);
}

.brand-mark { color: #e89965; font-size: 1.2em; }

.settings-hold {
  position: relative;
  min-height: 48px;
  padding: 8px 13px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 2px solid var(--line);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 750;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.hold-ring {
  position: absolute;
  inset: auto 0 0 0;
  height: 4px;
  transform: scaleX(0);
  transform-origin: left;
  background: #5d9168;
}

.settings-hold.holding .hold-ring { animation: hold-progress 1s linear forwards; }
@keyframes hold-progress { to { transform: scaleX(1); } }

.app-shell {
  width: min(1050px, 100%);
  margin: 0 auto;
  padding: clamp(18px, 4vw, 36px) max(16px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.screen-heading { text-align: center; margin-bottom: 24px; }
.screen-heading.compact { margin-bottom: 18px; }
.eyebrow {
  margin: 0 0 5px;
  color: #9a603b;
  font-weight: 850;
  letter-spacing: 0.08em;
}

h1, h2, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: clamp(2rem, 6vw, 3.4rem); line-height: 1.2; }
h2 { margin: 0; font-size: clamp(1.4rem, 4vw, 2rem); }
.screen-heading > p:last-child { margin: 10px auto 0; color: var(--muted); font-size: clamp(0.98rem, 2.5vw, 1.18rem); }

.main-card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(12px, 2.6vw, 22px);
}

.main-card {
  position: relative;
  min-height: 240px;
  padding: 10px 10px 16px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  border: 4px solid var(--category-color);
  border-radius: 28px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: var(--shadow);
  cursor: pointer;
  overflow: hidden;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.main-card:active { transform: scale(0.97); box-shadow: 0 4px 12px rgba(88, 63, 36, 0.12); }
.main-card[data-category="safety"] { --category-color: var(--safety); }
.main-card[data-category="daily"] { --category-color: var(--daily); }
.main-card[data-category="feeling"] { --category-color: var(--feeling); }

.card-category {
  position: absolute;
  top: 17px;
  left: 17px;
  z-index: 2;
  padding: 5px 11px;
  border-radius: 999px;
  color: #fff;
  background: var(--category-color);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.04em;
}

.main-card img {
  width: 100%;
  min-height: 0;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 18px;
  background: #fffaf2;
}

.card-label {
  display: block;
  padding-top: 10px;
  font-size: clamp(1.45rem, 4vw, 2.2rem);
  font-weight: 900;
  line-height: 1.1;
}

.privacy-note {
  width: fit-content;
  margin: 24px auto 0;
  padding: 9px 16px;
  border-radius: 999px;
  color: #5f665f;
  background: #edf5e9;
  font-weight: 700;
}

.message-layout { width: min(760px, 100%); margin: 0 auto; }
.message-card {
  padding: clamp(18px, 4vw, 32px);
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) 1.2fr;
  align-items: center;
  gap: clamp(18px, 5vw, 42px);
  border: 8px solid var(--main-red);
  border-radius: 36px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.message-card img { width: 100%; border-radius: 24px; }
.message-card .spoken-word { font-size: clamp(3rem, 11vw, 6.5rem); font-weight: 950; line-height: 1.1; }
.message-card .spoken-note { margin-top: 10px; color: var(--muted); font-size: 1.05rem; font-weight: 750; }
.message-actions { margin: 14px 0 20px; text-align: center; }

.partner-panel {
  padding: clamp(18px, 4vw, 28px);
  border: 3px dashed #cbb99f;
  border-radius: 28px;
  text-align: center;
  background: rgba(255, 255, 255, 0.74);
}

.partner-label {
  width: fit-content;
  margin: 0 auto 8px;
  padding: 5px 14px;
  border-radius: 999px;
  color: #685441;
  background: #eee4d5;
  font-size: 0.9rem;
  font-weight: 850;
}

.partner-actions { margin-top: 17px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.action-button,
.special-button {
  min-height: 68px;
  padding: 13px 18px;
  border: 0;
  border-radius: 20px;
  color: var(--ink);
  font-size: clamp(1.15rem, 3.5vw, 1.55rem);
  font-weight: 900;
  line-height: 1.25;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(83, 67, 49, 0.17);
}

.action-button:active,
.special-button:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(83, 67, 49, 0.17); }
.action-button.understood { color: #fff; background: #4e9566; }
.action-button.ask-more { background: #f0c260; }
.action-button.secondary { background: #e9e3db; }
.action-button.wide { width: min(460px, 100%); }

.message-strip {
  min-height: 96px;
  margin: 0 auto 18px;
  padding: 12px;
  display: flex;
  align-items: stretch;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  border-radius: 24px;
  background: #f0e9df;
}

.message-token {
  min-width: 150px;
  padding: 11px 18px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 4px solid transparent;
  color: #261f1a;
  text-align: center;
  font-size: clamp(1.3rem, 4vw, 1.85rem);
  font-weight: 900;
}

.message-token small { margin-bottom: 3px; font-size: 0.72rem; font-weight: 800; }
.message-token.main { border-radius: 18px; border-color: #983f3a; background: #f3a5a0; }
.message-token.reason { border-radius: 50% / 24%; border-color: #a37919; background: #f9df91; }
.message-token.request { border-radius: 18px 18px 6px 6px; border-color: #3f8051; background: #a9d7b2; }
.message-token.neutral { border-radius: 999px; border-color: #62588e; background: #c9c2e2; }

.detail-card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.detail-card {
  position: relative;
  min-height: 154px;
  padding: 40px 12px 14px;
  border: 5px solid var(--role-border);
  color: var(--ink);
  background: var(--role-bg);
  font-size: clamp(1.25rem, 3.6vw, 1.8rem);
  font-weight: 900;
  line-height: 1.35;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.detail-card[data-role="reason"] { --role-border: #a37919; --role-bg: #f9df91; border-radius: 50% / 24%; }
.detail-card[data-role="request"] { --role-border: #3f8051; --role-bg: #a9d7b2; border-radius: 24px 24px 8px 8px; }
.role-label {
  position: absolute;
  top: 9px;
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 10px;
  border-radius: 999px;
  color: #3d342a;
  background: rgba(255,255,255,0.64);
  font-size: 0.72rem;
  font-weight: 850;
  white-space: nowrap;
}

.special-actions { margin: 16px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.special-button { border: 4px solid #72699a; background: #d9d3ed; }
.special-button small { font-size: 0.72em; }
.detail-partner { margin-top: 17px; }

.success-screen { min-height: 64vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.success-screen[hidden] { display: none; }
.success-mark {
  width: 130px;
  height: 130px;
  margin-bottom: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: #5ca271;
  font-size: 5rem;
  font-weight: 900;
  box-shadow: var(--shadow);
}
.success-screen p { margin: 12px 0 28px; color: var(--muted); font-size: 1.2rem; }

.storage-boundary {
  margin: 0 auto 18px;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 2px solid #b6d1ae;
  border-radius: 18px;
  background: #eff7ec;
}
.storage-boundary strong { color: #3d7148; }
.character-setting {
  margin: 0 0 18px;
  padding: 14px 16px 16px;
  border: 2px solid #d7c6ae;
  border-radius: 20px;
  background: var(--paper);
}
.character-setting legend { padding: 0 8px; color: var(--muted); font-weight: 850; }
.character-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.character-options label {
  min-height: 70px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 3px solid var(--line);
  border-radius: 18px;
  cursor: pointer;
  font-size: 1.08rem;
}
.character-options label:has(input:checked) { border-color: #4e9566; background: #eef7eb; }
.character-options input { width: 25px; height: 25px; accent-color: #4e9566; }
.settings-list { display: grid; gap: 14px; }
.settings-card { padding: 16px; border: 2px solid var(--line); border-radius: 20px; background: var(--paper); }
.settings-main-row { display: flex; align-items: center; gap: 12px; }
.settings-main-row label { display: flex; align-items: center; gap: 10px; flex: 1; font-size: 1.2rem; font-weight: 850; }
.settings-main-row input,
.detail-setting input { width: 26px; height: 26px; accent-color: #4e9566; }
.move-buttons { display: flex; gap: 7px; }
.move-button { min-width: 48px; min-height: 46px; border: 2px solid var(--line); border-radius: 12px; background: #f2ece4; font-weight: 900; cursor: pointer; }
.detail-settings { margin: 14px 0 0 38px; padding: 12px 14px; border-left: 4px solid #d9c9b4; }
.detail-settings legend { padding: 0 7px; color: var(--muted); font-weight: 800; }
.detail-setting { margin: 9px 0; display: flex; align-items: center; gap: 9px; }
.settings-actions { margin-top: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.settings-actions .text-button { grid-column: 1 / -1; }
.text-button { min-height: 48px; border: 0; color: #8e4c47; background: transparent; text-decoration: underline; font-weight: 800; cursor: pointer; }
.settings-error { min-height: 1.5em; margin: 12px 0 0; color: #a13f38; font-weight: 850; text-align: center; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 20;
  max-width: calc(100% - 32px);
  padding: 12px 20px;
  border-radius: 999px;
  color: #fff;
  background: rgba(52, 43, 36, 0.92);
  font-weight: 800;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, 120px);
  transition: transform 180ms ease, opacity 180ms ease;
}
.toast.show {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

@media (max-width: 720px) {
  .app-header { align-items: stretch; }
  .settings-hold span:nth-child(2) { display: none; }
  .main-card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .main-card { min-height: 200px; border-radius: 23px; }
  .message-card { grid-template-columns: 1fr; text-align: center; }
  .message-card img { width: min(340px, 100%); margin: 0 auto; }
  .detail-card-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 430px) {
  .app-shell { padding-left: 11px; padding-right: 11px; }
  .main-card-grid { gap: 9px; }
  .main-card { min-height: 178px; padding: 7px 7px 12px; border-width: 3px; }
  .main-card img { border-radius: 14px; }
  .card-category { top: 11px; left: 11px; padding: 4px 8px; font-size: 0.66rem; }
  .partner-actions,
  .special-actions,
  .settings-actions { grid-template-columns: 1fr; }
  .settings-actions .text-button { grid-column: auto; }
  .detail-card-grid { grid-template-columns: 1fr; }
  .character-options { grid-template-columns: 1fr; }
}

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