/* ══════════════════════════════════════════════════════════
   Polair Tarot — DESIGN SYSTEM
   Soft grid · gallery minimal · transcript chat
   ══════════════════════════════════════════════════════════ */

@font-face {
  font-family: 'Reckless Condensed';
  src: url('fonts/RecklessCondensed-Thin.otf') format('opentype');
  font-weight: 300;
  font-display: swap;
}

:root {
  --bg: #FAF8F4;
  --ink: #2B2A27;
  --ink-soft: #8A8578;
  --ink-mid: #4A4740;
  --accent: #C98A73;
  --line: rgba(43,42,39,0.12);
  --line-soft: rgba(43,42,39,0.08);
  --font-display: 'Instrument Sans', sans-serif;
  --font-headline: 'Reckless Condensed', 'Instrument Sans', serif;
  --font-body: 'Inter', -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 393px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
}

/* ── Favicon loading state ── */
.app-loader {
  align-items: center;
  background: rgba(250, 248, 244, 0.94);
  display: flex;
  flex-direction: column;
  inset: 0;
  justify-content: center;
  position: fixed;
  z-index: 1000;
}
.app-loader[hidden] { display: none; }
.app-loader-mark {
  align-items: center;
  display: flex;
  height: 54px;
  justify-content: center;
  position: relative;
  width: 54px;
  animation: loaderBreath 1.35s ease-in-out infinite;
}
.app-loader-mark img {
  display: block;
  height: 100%;
  object-fit: contain;
  width: 100%;
}
.app-loader-fallback {
  color: var(--ink);
  font-family: var(--font-headline);
  font-size: 22px;
  font-weight: 300;
}
.app-loader-fallback[hidden] { display: none; }
@keyframes loaderBreath {
  0%, 100% { opacity: 0.55; transform: scale(0.82); }
  50% { opacity: 1; transform: scale(1.08); }
}

.screen {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.screen:not([hidden]) {
  display: flex;
  animation: screenFade 0.32s ease both;
}
@keyframes screenFade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Tactile feedback ── */
.intent-card, .intent-step, .spread-option, .deck-card, .primary-btn, .secondary-btn, .send-btn, .suggest-chip, .icon-btn {
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.intent-card:active, .intent-step:active, .spread-option:active, .primary-btn:active, .secondary-btn:active, .send-btn:active, .suggest-chip:active {
  opacity: 0.6;
  transform: scale(0.98);
}

/* ── Topbar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 0;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 500;
}
.wordmark {
  align-items: center;
  display: flex;
  height: 56px;
  justify-content: center;
  width: 56px;
}
.wordmark img {
  display: block;
  height: 100%;
  object-fit: contain;
  width: 100%;
  /* Giúp nền be của favicon hòa với nền giấy của giao diện. */
  mix-blend-mode: multiply;
}
.icon-btn {
  background: none;
  border: none;
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 4px;
}
.topbar-spacer { width: 24px; display: inline-block; }
.rule { height: 1px; background: var(--line); margin: 16px 0 0; }

/* ── Section label (A)(B) ── */
.eyebrow, .section-label {
  text-align: left;
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 20px 20px 0;
}
.eyebrow .paren, .section-label .paren { color: var(--accent); }

.page-title {
  font-family: var(--font-headline);
  font-weight: 300;
  font-size: 34px;
  line-height: 1.08;
  padding: 6px 20px 0;
  letter-spacing: 0.001em;
}
.page-sub {
  color: var(--ink-soft);
  font-size: 13px;
  padding: 8px 20px 0;
}

/* ── Home: daily landscape triptych + stepped topics ── */
.home-hero { padding-bottom: 6px; }
.home-gallery {
  align-items: start;
  display: grid;
  column-gap: 18px;
  grid-template-areas: "small wide";
  grid-template-columns: minmax(0, 0.56fr) minmax(0, 1fr);
  padding: 8px 24px 26px;
}
.home-landscape {
  margin: 0;
  overflow: hidden;
  position: relative;
}
.home-landscape img {
  aspect-ratio: 1 / 1;
  display: block;
  filter: grayscale(1) contrast(0.92) brightness(1.04);
  object-fit: cover;
  width: 100%;
}
.home-landscape.landscape-1 {
  grid-area: small;
  margin-top: 24px;
}
.home-landscape.landscape-2 {
  grid-area: wide;
}
.home-landscape.landscape-2 img {
  aspect-ratio: 1.72 / 1;
}
.home-gallery-bottom {
  padding: 18px 24px 36px;
}
.home-gallery-bottom .home-landscape {
  margin: 0;
}
.home-gallery-bottom .home-landscape img {
  aspect-ratio: 2.2 / 1;
}
.intent-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0 20px 28px;
}
.intent-step {
  background: var(--bg);
  border: none;
  border-top: 1px solid var(--line);
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: baseline;
  appearance: none;
  gap: 12px;
  padding: 13px 0 12px;
  text-align: left;
  transition: padding-left 0.2s ease, background-color 0.2s ease;
  -webkit-appearance: none;
}
.intent-step:last-child { border-bottom: 1px solid var(--line); }
.intent-step:hover,
.intent-step:focus-visible {
  background: rgba(201, 138, 115, 0.06);
  padding-left: 8px;
}
.intent-step.step-2 { margin-left: 13%; }
.intent-step.step-3 { margin-left: 7%; }
.intent-step.step-4 { margin-left: 20%; }
.intent-step .step-number {
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 10px;
  width: 24px;
}
.intent-step .step-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.intent-step .label {
  color: var(--ink);
  font-family: var(--font-headline);
  font-size: 21px;
  font-weight: 300;
  line-height: 1;
}
.intent-step .sub {
  color: var(--ink-soft);
  font-size: 11px;
}
.intent-step .step-number,
.intent-step .step-arrow {
  color: var(--accent);
}
.intent-step .step-arrow {
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 14px;
  margin-left: auto;
}

/* ── Spread list ── */
.spread-hero { padding-bottom: 6px; }
.spread-list { padding: 18px 20px 24px; display: flex; flex-direction: column; }
.spread-option {
  background: none;
  border: none;
  border-top: 1px solid var(--line-soft);
  padding: 16px 0;
  display: flex;
  align-items: baseline;
  gap: 12px;
  cursor: pointer;
  text-align: left;
}
.spread-option:last-child { border-bottom: 1px solid var(--line-soft); }
.spread-option .emoji { font-family: var(--font-display); font-size: 11px; color: var(--accent); width: 18px; flex-shrink: 0; }
.spread-option .name { font-family: var(--font-display); font-weight: 500; font-size: 14px; color: var(--ink); }
.spread-option .desc { color: var(--ink-soft); font-size: 12px; margin-top: 3px; }

/* ── Draw screen: nghi thức "chụp ảnh" → lắc lộ bài ── */
.upload-btn-label {
  background: none;
  border: 1px dashed var(--accent);
  font-family: var(--font-display);
  font-size: 10.5px;
  padding: 5px 12px;
  cursor: pointer;
  color: var(--accent);
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
}

.viewfinder-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 20px 0;
  min-height: 0;
}
.viewfinder-frame {
  width: 100%;
  max-width: 320px;
  aspect-ratio: 3 / 3.6;
  background: var(--ink);
  position: relative;
  overflow: hidden;
  cursor: crosshair;
  flex-shrink: 0;
}
.scenery-base {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: grayscale(0.15) saturate(1.05) contrast(1.02);
}
.lens-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(0,0,0,0) 45%, rgba(43,42,39,0.55) 100%);
  pointer-events: none;
}
#vf-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hud-layer {
  position: absolute;
  inset: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
  font-family: var(--font-display);
  font-size: 9px;
  color: rgba(250,248,244,0.9);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.hud-row { display: flex; justify-content: space-between; }
.hud-lock-badge { color: var(--accent); opacity: 0; font-weight: 600; }
.hud-lock-badge.active { opacity: 1; }
.shutter-flash {
  position: absolute; inset: 0;
  background: var(--bg);
  opacity: 0;
  pointer-events: none;
}
.shutter-flash.fire { animation: flashAnim 0.35s ease-out forwards; }
@keyframes flashAnim { 0% { opacity: 1; } 100% { opacity: 0; } }

.draw-note {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--ink-soft);
  margin: 10px 0 0;
  text-align: center;
}

.polaroid-tray { display: flex; gap: 8px; margin: 14px 0 6px; justify-content: center; flex-wrap: wrap; }
@keyframes trayShake {
  0% { transform: translate(0,0) rotate(0); }
  20% { transform: translate(-6px,3px) rotate(-1.5deg); }
  40% { transform: translate(6px,-3px) rotate(1.5deg); }
  60% { transform: translate(-4px,2px) rotate(-1deg); }
  80% { transform: translate(4px,-2px) rotate(1deg); }
  100% { transform: translate(0,0) rotate(0); }
}
.polaroid-tray.shaking-tray { animation: trayShake 0.4s ease-in-out; }
.tray-slot {
  width: 72px;
  height: 108px;
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 4px 4px 6px;
  display: flex;
  flex-direction: column;
  opacity: 0.4;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.tray-slot.filled { opacity: 1; transform: translateY(-3px); }
.card-morph-stage { width: 100%; flex: 1; background: var(--ink); position: relative; overflow: hidden; }
.cropped-photo-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  filter: grayscale(1) contrast(1.3) brightness(0.95);
  transition: opacity 0.5s ease, filter 0.5s ease, transform 0.5s ease;
}
.tarot-underlayer {
  position: absolute; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transform: scale(0.92);
  transition: opacity 0.5s ease, transform 0.5s ease;
  overflow: hidden;
}
.tarot-underlayer img { width: 100%; height: 100%; object-fit: cover; }
.slot-meta { font-family: var(--font-display); font-size: 8.5px; text-align: center; margin-top: 4px; color: var(--ink-soft); }

.shake-progress-bar-container {
  width: 100%; max-width: 240px; height: 2px;
  background: var(--line); margin: 6px 0; overflow: hidden;
}
.shake-progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.2s ease-out; }

.controls-wrapper { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 6px 0 18px; }
.shutter-ring {
  width: 60px; height: 60px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; background: none;
}
.shutter-ring:active { transform: scale(0.92); }
.shutter-btn { width: 44px; height: 44px; background: var(--ink); border-radius: 50%; }
.btn-manual-shake {
  background: var(--accent); color: var(--bg); border: none;
  font-family: var(--font-display); font-size: 11px; font-weight: 500;
  padding: 12px 22px; cursor: pointer; border-radius: 24px;
  animation: pulseBtn 1.8s infinite ease-in-out;
}
@keyframes pulseBtn { 0%,100% { transform: scale(1); } 50% { transform: scale(1.03); } }
.shutter-hint { font-family: var(--font-display); font-size: 11px; color: var(--ink-soft); text-align: center; }

.primary-btn, .secondary-btn {
  display: block;
  width: calc(100% - 40px);
  margin: 16px 20px;
  padding: 15px;
  border-radius: 0;
  border: 1px solid var(--ink);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  letter-spacing: 0.02em;
}
.primary-btn { background: var(--ink); color: var(--bg); }
.secondary-btn { background: none; color: var(--ink); }

/* ── Chat: hero card (focus point) + transcript ── */
.drawn-cards-strip {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  overflow-x: auto;
  padding: 16px 20px 0;
  scrollbar-width: none;
}
.drawn-cards-strip::-webkit-scrollbar { display: none; }
.drawn-cards-strip .hero-card {
  width: 76px;
  height: 118px;
  object-fit: cover;
  display: block;
  filter: grayscale(0.7) sepia(0.06) contrast(0.95) brightness(1.03);
  flex: 0 0 auto;
}
.drawn-cards-strip .rest {
  display: flex;
  gap: 6px;
  padding-top: 1px;
}
.drawn-cards-strip .rest img {
  width: 40px;
  height: 62px;
  object-fit: cover;
  filter: grayscale(0.7) sepia(0.06);
  flex-shrink: 0;
}

/* ── Chat stream ── */
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 20px 10px;
}

/* ── First reading: newspaper-like editorial layout ── */
.reading-article {
  padding: 2px 0 22px;
  animation: msgFade 0.28s ease both;
}
.reading-kicker {
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  margin-bottom: 12px;
}
.reading-quote {
  font-family: var(--font-headline);
  font-size: 31px;
  font-weight: 300;
  font-style: italic;
  font-synthesis: style;
  line-height: 1.08;
  letter-spacing: -0.012em;
  padding-bottom: 20px;
  position: relative;
}
.reading-quote::before {
  color: var(--accent);
  content: "“";
  font-family: Georgia, serif;
  font-size: 54px;
  left: -3px;
  line-height: 0;
  position: relative;
  top: 15px;
}
.reading-quote::after {
  color: var(--accent);
  content: "”";
  font-family: Georgia, serif;
}
.article-section {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(76px, 92px) minmax(0, 1fr);
  padding: 16px 0 2px;
}
.article-section.media-left {
  grid-template-columns: minmax(0, 1fr) minmax(76px, 92px);
}
.article-section.media-left .article-figure {
  grid-column: 2;
  grid-row: 1;
}
.article-section.media-left .article-copy {
  grid-column: 1;
  grid-row: 1;
}
.article-section.without-image {
  display: block;
}
.article-figure {
  margin: 0;
}
.article-figure img {
  aspect-ratio: 0.64;
  display: block;
  filter: grayscale(0.52) sepia(0.08) contrast(0.96) brightness(1.03);
  object-fit: cover;
  width: 100%;
}
.article-figure figcaption {
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 9px;
  line-height: 1.25;
  margin-top: 6px;
}
.article-section h3 {
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  line-height: 1.3;
  margin-bottom: 10px;
}
.article-copy p {
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.72;
  margin-bottom: 12px;
}
.article-copy p:last-child { margin-bottom: 4px; }
.article-copy .drop-cap::first-letter {
  color: var(--ink);
  float: left;
  font-family: var(--font-headline);
  font-size: 52px;
  font-weight: 300;
  line-height: 0.78;
  margin: 7px 7px 0 0;
}
.msg {
  display: flex;
  gap: 17px;
  margin-bottom: 18px;
  align-items: flex-start;
  animation: msgFade 0.28s ease both;
}
@keyframes msgFade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg .tag {
  font-family: var(--font-display);
  font-size: 10.5px;
  color: var(--accent);
  line-height: 1.2;
  white-space: normal;
  padding-top: 2px;
  width: 72px;
  flex-shrink: 0;
}
.msg.user .tag { color: var(--ink-soft); }
.msg .txt {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink);
  white-space: pre-wrap;
}
.msg.typing .txt::after {
  content: "···";
  color: var(--ink-soft);
  animation: blink 1.2s infinite ease-in-out;
}
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

@media (max-width: 340px) {
  .msg { gap: 12px; }
  .msg .tag { width: 60px; }
  .reading-quote { font-size: 27px; }
}

.suggest-chips {
  padding: 4px 20px 14px;
  border-top: 1px solid var(--line-soft);
  margin-top: 4px;
}
.suggest-chip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: none;
  border: none;
  border-bottom: 1px solid var(--line-soft);
  padding: 12px 0;
  font-size: 13px;
  color: var(--ink-mid);
  text-align: left;
  cursor: pointer;
  font-family: var(--font-body);
}
.suggest-chip::before {
  content: counter(chip-count, decimal-leading-zero) " ";
  counter-increment: chip-count;
  font-family: var(--font-display);
  color: var(--accent);
  font-size: 11px;
  margin-right: 10px;
}
.suggest-chips { counter-reset: chip-count; }

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0));
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  background: rgba(43,42,39,0.03);
  border-radius: 20px;
  padding: 11px 16px;
  font-size: 13.5px;
  line-height: 1.4;
  font-family: var(--font-body);
  color: var(--ink);
  max-height: 100px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.chat-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg);
}
.chat-input::placeholder { color: var(--ink-soft); }
.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--ink);
  color: var(--bg);
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.1s ease;
}
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled {
  background: var(--line);
  color: var(--ink-soft);
  cursor: default;
}

/* ── History screen ── */
.history-list { padding: 18px 20px 24px; }
.history-item {
  border-top: 1px solid var(--line-soft);
  padding: 14px 0;
  cursor: pointer;
}
.history-item:last-child { border-bottom: 1px solid var(--line-soft); }
.history-item .date { font-family: var(--font-display); font-size: 10.5px; color: var(--accent); }
.history-item .summary { font-size: 13px; margin-top: 4px; color: var(--ink); }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0));
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  font-family: var(--font-display);
  font-size: 12px;
  z-index: 999;
  max-width: 90%;
  text-align: center;
}
