/* Vabrix Private Room — visual design
   Direction: Japanese-inspired calm (ma / negative space, wabi-sabi warmth,
   restrained sakura accent on warm paper). Sans-serif, very readable. */

:root {
  /* Typeface: warm, legible Japanese-designed gothic, with safe system fallback. */
  --font: "Zen Kaku Gothic New", ui-sans-serif, system-ui, -apple-system,
          "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Palette — paper, ink, and a single soft sakura/salmon accent. */
  --bg: #f4efe9;          /* warm paper (kinari) */
  --paper: #fdfbf7;       /* lifted paper for cards/sheets */
  --ink: #2b2521;         /* sumi ink, slightly warm */
  --muted: #8c7d72;       /* quiet secondary text */
  --accent: #c97c69;      /* sakura / muted coral accent */
  --accent-soft: #f3ddd2; /* soft salmon fill */
  --accent-mist: #f7e7df; /* lightest salmon wash */
  --line: rgba(43, 37, 33, 0.10);
  --line-strong: rgba(43, 37, 33, 0.16);

  --shadow-soft: 0 12px 40px rgba(43, 37, 33, 0.10);
  --shadow-card: 0 10px 28px rgba(43, 37, 33, 0.09);
  --shadow-lift: 0 18px 50px rgba(43, 37, 33, 0.16);

  --radius: 20px;
  --radius-sm: 14px;
  --tap: 46px;

  /* Shared heart silhouette (used as a CSS mask for the header icon). */
  --heart-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z'/%3E%3C/svg%3E");
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  /* Calm, almost-flat paper wash — restraint over drama. */
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(255, 255, 255, 0.6), transparent 60%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 700px);
  margin: 0 auto;
  padding-bottom: 40px;
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: var(--tap) 1fr auto;
  align-items: center;
  gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 16px 14px;
  background: rgba(244, 239, 233, 0.82);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}

.brand {
  text-align: center;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-weight: 500;
  font-size: clamp(1.1rem, 4.6vw, 1.4rem);
  line-height: 1.1;
  letter-spacing: 0.06em;
}

.brand p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-button,
.heart-button,
.modal-close,
.plain-button {
  border: 0;
  color: var(--ink);
  background: var(--paper);
  border-radius: 999px;
  min-width: var(--tap);
  min-height: var(--tap);
  box-shadow: var(--shadow-card);
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.icon-button {
  font-size: 1.05rem;
}

.icon-button:active,
.heart-button:active,
.modal-close:active,
.plain-button:active {
  transform: scale(0.94);
}

/* Header favorites button: little heart + count. */
/* Favorites button: a circle by default. With 2+ hearts it springs open into a
   pill so the number gets its own room and never squeezes the heart. */
.heart-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: auto;
  min-width: var(--tap);
  max-width: var(--tap);   /* keeps it a perfect circle when collapsed */
  height: var(--tap);
  padding: 0;
  color: var(--accent);
  font-weight: 700;
  overflow: hidden;
  /* Soft springy easing for the elongation. */
  transition:
    max-width 320ms cubic-bezier(0.34, 1.56, 0.64, 1),
    padding 320ms cubic-bezier(0.34, 1.56, 0.64, 1),
    gap 240ms ease,
    transform 140ms ease,
    box-shadow 140ms ease;
}

.heart-button::before {
  content: "";
  flex: none;
  width: 19px;
  height: 19px;
  background-color: currentColor; /* sakura accent */
  -webkit-mask: var(--heart-mask) center / contain no-repeat;
          mask: var(--heart-mask) center / contain no-repeat;
}

/* The count slides in only when the pill is open; sized to match the heart. */
.heart-button span {
  flex: none;
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
  transition:
    max-width 300ms cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity 200ms ease;
}

.heart-button.is-expanded {
  gap: 7px;
  padding: 0 17px;
  max-width: 130px;
}

.heart-button.is-expanded span {
  max-width: 3ch;
  opacity: 1;
}

/* ---------- Active filter pills ---------- */

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 16px 4px;
}

.active-filters:empty {
  padding: 0;
}

.active-filters .active-pill {
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--accent-mist);
  color: #8a5848;
  font-size: 0.76rem;
  letter-spacing: 0.02em;
}

/* ---------- Item grid ---------- */

.item-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px 14px;
  padding: 16px 14px 28px;
}

.item-card {
  position: relative;
  animation: cardIn 360ms ease both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.item-open {
  border: 0;
  padding: 0;
  width: 100%;
  background: transparent;
  text-align: left;
}

.item-photo-wrap {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-sm);
  aspect-ratio: 3 / 4;
  background: var(--accent-mist);
  box-shadow: var(--shadow-card);
}

.item-photo {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform 420ms ease;
}

.item-open:active .item-photo {
  transform: scale(1.02);
}

.price-badge,
.detail-price {
  position: absolute;
  right: 9px;
  bottom: 9px;
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(253, 251, 247, 0.92);
  backdrop-filter: blur(6px);
  color: var(--ink);
  font-weight: 700;
  font-size: 0.86rem;
  letter-spacing: 0.01em;
  box-shadow: 0 4px 14px rgba(43, 37, 33, 0.12);
}

.item-caption {
  padding: 10px 4px 0;
}

.item-caption h2 {
  margin: 0;
  font-weight: 500;
  font-size: 0.92rem;
  line-height: 1.25;
  letter-spacing: 0.01em;
}

.item-caption p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Heart buttons (card + detail) ---------- */

.card-heart {
  position: absolute;
  top: 9px;
  right: 9px;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: rgba(253, 251, 247, 0.9);
  backdrop-filter: blur(6px);
  color: var(--ink);
  box-shadow: 0 4px 14px rgba(43, 37, 33, 0.14);
  transition: transform 160ms ease, background 160ms ease;
}

/* Explicit px (not %) so older Safari on iOS sizes the heart correctly.
   ~64% of each circle, matching the previous Android-Chrome look. */
.card-heart svg {
  width: 26px;
  height: 26px;
  display: block;
}

.detail-heart svg {
  width: 34px;
  height: 34px;
  display: block;
}

/* Outline by default, filled sakura when liked. */
.card-heart svg path,
.detail-heart svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.1;
  stroke-linejoin: round;
  transition: fill 160ms ease;
}

.card-heart.is-liked,
.detail-heart.is-liked {
  color: var(--accent);
}

.card-heart.is-liked svg path,
.detail-heart.is-liked svg path {
  fill: currentColor;
}

/* Gentle pop when toggled. */
.heart-pop {
  animation: heartPop 320ms ease;
}

@keyframes heartPop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.28); }
  60%  { transform: scale(0.92); }
  100% { transform: scale(1); }
}

/* ---------- Empty state ---------- */

/* Invisible trigger that sits just under the grid. */
.scroll-sentinel {
  height: 1px;
  width: 100%;
}

.loading-more {
  margin: 0;
  padding: 2px 0 26px;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
}

.loading-more[hidden] {
  display: none;
}

.empty-state {
  margin: 36px 16px;
  padding: 30px 24px;
  border-radius: var(--radius);
  text-align: center;
  background: var(--paper);
  color: var(--muted);
  box-shadow: var(--shadow-soft);
}

/* ---------- Filter drawer ---------- */

.filter-drawer {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 60;
  width: min(86vw, 360px);
  overflow-y: auto;
  padding: max(20px, env(safe-area-inset-top)) 20px 30px;
  background: var(--paper);
  box-shadow: var(--shadow-lift);
  transform: translateX(-105%);
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

.filter-drawer.is-open {
  transform: translateX(0);
}

.drawer-shade,
.modal-backdrop,
.welcome-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(43, 37, 33, 0.32);
  backdrop-filter: blur(3px);
  animation: fadeIn 200ms ease both;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.filter-header,
.favorites-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.filter-header h2,
.favorites-header h2 {
  margin: 0;
  font-weight: 500;
  font-size: 1.3rem;
  letter-spacing: 0.02em;
}

.favorites-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.plain-button {
  min-width: auto;
  padding: 0 14px;
  font-size: 0.84rem;
  color: var(--muted);
}

.filter-section {
  padding: 22px 0 6px;
  border-top: 1px solid var(--line);
}

.filter-section:first-of-type {
  border-top: 0;
}

.filter-section h3 {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.chip {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: #5a4d44;
  border-radius: 999px;
  padding: 9px 14px;
  min-height: 40px;
  font-size: 0.86rem;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease;
}

.chip.is-selected {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.wide-button,
.primary-button,
.secondary-button {
  border: 0;
  border-radius: 999px;
  min-height: 46px;
  padding: 0 18px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.wide-button {
  width: 100%;
  margin-top: 24px;
  background: var(--accent-soft);
  color: #7d4a3a;
}

/* ---------- Drawer settings ---------- */

.drawer-separator {
  height: 1px;
  margin: 26px 0 6px;
  background: var(--line);
}

.settings-section {
  padding: 14px 0 6px;
}

.settings-section h3 {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

/* A generous, tappable settings row with an on/off switch. */
.setting-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-radius: var(--radius-sm);
  background: rgba(43, 37, 33, 0.04);
  cursor: pointer;
}

.setting-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.setting-title {
  font-size: 0.98rem;
  font-weight: 500;
}

.setting-sub {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

/* The switch — a styled checkbox. */
.switch {
  position: relative;
  flex: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.switch-track {
  display: block;
  width: 56px;
  height: 32px;
  border-radius: 999px;
  background: rgba(43, 37, 33, 0.22);
  transition: background 200ms ease;
}

.switch-thumb {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 3px 8px rgba(43, 37, 33, 0.28);
  transition: transform 220ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(24px);
}

.switch input:disabled ~ .switch-track,
.switch input:disabled {
  cursor: default;
}

.setting-toggle:has(input:disabled) {
  opacity: 0.6;
  cursor: default;
}

.setting-hint {
  margin: 12px 2px 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.setting-hint[hidden] {
  display: none;
}

/* ---------- Detail view ---------- */

.modal[hidden],
.favorites-panel[hidden],
.welcome[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
}

.detail-sheet {
  position: fixed;
  inset: 0;
  z-index: 110;
  background: #1a1613;
  animation: fadeIn 220ms ease both;
}

.detail-sheet .modal-close,
.detail-heart {
  position: absolute;
  z-index: 130;
  top: max(14px, env(safe-area-inset-top));
  /* Bumped 46->54 so the controls read clearly on smaller phones. */
  width: 54px;
  height: 54px;
  border: 0;
  border-radius: 999px;
  background: rgba(253, 251, 247, 0.9);
  backdrop-filter: blur(6px);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
}

.detail-sheet .modal-close {
  right: 14px;
  font-size: 2.1rem;
  line-height: 1;
  color: var(--ink);
}

/* Single heart, fixed beside the close button — stays put across slides.
   Sits at 80px so its 54px circle clears the 54px close button (~12px gap). */
.detail-heart {
  right: 80px;
  display: grid;
  place-items: center;
  color: var(--ink);
}

/* Share-this-piece button, fixed top-left (mirrors the close button). */
.detail-share {
  position: absolute;
  z-index: 130;
  top: max(14px, env(safe-area-inset-top));
  left: 14px;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: rgba(253, 251, 247, 0.9);
  backdrop-filter: blur(6px);
  color: var(--ink);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
  transition: transform 140ms ease;
}

.detail-share:active {
  transform: scale(0.94);
}

.detail-share svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}

.detail-carousel {
  height: 100%;
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.detail-carousel::-webkit-scrollbar {
  display: none;
}

.detail-slide {
  position: relative;
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  scroll-snap-align: start;
  display: grid;
  place-items: center;
  background: #1a1613;
}

.detail-slide img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.text-slide {
  background:
    radial-gradient(120% 70% at 50% 0%, rgba(255, 255, 255, 0.6), transparent 60%),
    var(--accent-mist);
  color: var(--ink);
  padding: 40px 28px;
  align-content: center;
}

.text-card {
  max-width: 520px;
  margin: auto;
  background: rgba(253, 251, 247, 0.66);
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 36px 30px 64px;
  position: relative;
}

.text-card h2 {
  margin: 0 0 16px;
  font-weight: 500;
  font-size: 1.7rem;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.text-card p {
  margin: 0;
  color: #4a3e36;
  font-size: 1.04rem;
  line-height: 1.65;
}

/* ---------- Favorites sheet ---------- */

.favorites-panel {
  position: fixed;
  inset: 0;
  z-index: 100;
}

.favorites-sheet {
  position: fixed;
  inset: auto 0 0;
  z-index: 110;
  width: min(100%, 700px);
  margin: 0 auto;
  max-height: 88vh;
  overflow-y: auto;
  padding: 22px 16px calc(116px + env(safe-area-inset-bottom));
  background: var(--paper);
  border-radius: 28px 28px 0 0;
  box-shadow: var(--shadow-lift);
  animation: sheetUp 260ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes sheetUp {
  from { transform: translateY(14px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.favorites-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.favorite-row {
  display: grid;
  grid-template-columns: 30px 64px 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 80px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: rgba(43, 37, 33, 0.035);
}

.favorite-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.favorite-row img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 12px;
}

.favorite-row h3 {
  margin: 0;
  font-weight: 500;
  font-size: 0.95rem;
  line-height: 1.2;
}

.favorite-row p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.favorite-price {
  font-weight: 700;
  white-space: nowrap;
}

.favorites-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 16px;
}

.secondary-button {
  background: var(--accent-mist);
  color: #7d4a3a;
  flex: 1;
}

.message-actions {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 120;
  width: min(100%, 700px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 9px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  background: rgba(253, 251, 247, 0.92);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}

.primary-button {
  background: var(--ink);
  color: var(--paper);
}

.primary-button.soft {
  background: #9a6253;
}

.primary-button.pale {
  background: var(--accent-soft);
  color: #7d4a3a;
}

/* ---------- Welcome (first visit) ---------- */

.welcome {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 22px;
}

/* Welcome backdrop sits below its card (the shared rule sets z-index:50). */
.welcome-backdrop {
  z-index: 0;
}

.welcome-card {
  position: relative;
  z-index: 1;
  width: min(100%, 440px);
  max-height: 86vh;
  overflow-y: auto;
  padding: 34px 30px 30px;
  background: var(--paper);
  border-radius: 24px;
  box-shadow: var(--shadow-lift);
  animation: sheetUp 320ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.welcome-logo {
  display: block;
  width: 84px;
  height: 84px;
  margin: 0 auto 14px;
  border-radius: 999px;
}

.welcome-card p {
  margin: 0 0 14px;
  color: #4a3e36;
  font-size: 1rem;
  line-height: 1.65;
}

.welcome-greeting {
  font-size: 1.5rem !important;
  font-weight: 500;
  color: var(--ink) !important;
  letter-spacing: 0.01em;
}

.welcome-sign {
  margin-top: 20px !important;
  color: var(--accent) !important;
  font-weight: 500;
  line-height: 1.5 !important;
}

.welcome-button {
  margin-top: 10px;
  width: 100%;
  border: 0;
  border-radius: 999px;
  min-height: 48px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 700;
  letter-spacing: 0.02em;
  transition: transform 140ms ease;
}

.welcome-button:active {
  transform: scale(0.97);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  z-index: 180;
  transform: translate(-50%, 120px);
  opacity: 0;
  max-width: min(90vw, 420px);
  padding: 11px 16px;
  border-radius: 999px;
  background: rgba(43, 37, 33, 0.94);
  color: var(--paper);
  font-size: 0.88rem;
  transition: transform 200ms ease, opacity 200ms ease;
  pointer-events: none;
}

.toast.is-visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

.noscript {
  padding: 24px;
}

/* ---------- Desktop note ---------- */

@media (min-width: 760px) {
  body::before {
    content: "This room is designed phone-first. Narrow the window or open it on a phone for the intended feeling.";
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 210;
    max-width: 260px;
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(43, 37, 33, 0.82);
    color: #fff;
    font-size: 0.8rem;
    line-height: 1.4;
  }
}
