/* Photo Random 抽牌頁
   概念:照片決定房間的顏色。--ambient 由 JS 從目前這張照片取色,其餘介面維持中性。 */

@property --ambient {
  syntax: '<color>';
  inherits: true;
  initial-value: #b9b4aa;
}

:root {
  --ink: #1f1e1c;
  --base: #e9e7e2;
  --paper: #fcfbf8;
  --mute: #4f4b45;
  --danger: #c2413b;
  --rule: color-mix(in oklab, var(--ink) 14%, transparent);
  --wash: 34%;
  --serif: 'Bodoni Moda', 'Noto Serif TC', 'Songti TC', serif;
  --sans: 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', system-ui, sans-serif;
  --flip-out: 200ms;
  --flip-in: 280ms;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #ecebe7;
    --base: #1c1b19;
    --paper: #efede8;
    --mute: #bcb8af;
    --wash: 24%;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #ecebe7;
  --base: #1c1b19;
  --paper: #efede8;
  --mute: #bcb8af;
  --wash: 24%;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100svh;
  font: 400 15px/1.6 var(--sans);
  color: var(--ink);
  background: color-mix(in oklab, var(--ambient) var(--wash), var(--base));
  transition: --ambient 900ms ease;
  -webkit-font-smoothing: antialiased;
}

:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

/* ---------- 版面 ---------- */
.shell {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 100svh;
}
@media (min-width: 900px) {
  .shell { grid-template-columns: 248px 1fr; }
}

/* ---------- 分類欄 ---------- */
.rail {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 16px 4px;
  min-width: 0;
}
.wordmark {
  font: 500 22px/1.1 var(--serif);
  font-optical-sizing: auto;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.decks {
  display: flex;
  gap: 4px 20px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -16px;
  padding: 4px 16px 6px;
  scroll-padding-inline: 16px;
}
.decks::-webkit-scrollbar { display: none; }
.deck {
  flex: none;
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 8px 0 6px;
  min-height: 44px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--mute);
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.deck-name {
  font: 400 21px/1.15 var(--serif);
  font-optical-sizing: auto;
}
.deck-count {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.deck:hover { color: var(--ink); }
.deck[aria-pressed="true"] { color: var(--ink); border-bottom-color: currentColor; }
.deck[aria-pressed="true"] .deck-name { font-weight: 600; }

.upload-link {
  position: absolute;
  top: 18px;
  right: 16px;
  font-size: 14px;
  color: var(--ink);
  text-underline-offset: 4px;
  padding: 2px 0;
}

@media (min-width: 900px) {
  .rail {
    position: sticky;
    top: 0;
    height: 100svh;
    padding: 40px 28px 32px 40px;
    gap: 36px;
  }
  .wordmark { font-size: 28px; }
  .decks {
    flex-direction: column;
    overflow: visible;
    margin: 0;
    padding: 0;
    gap: 2px;
  }
  .deck {
    justify-content: space-between;
    border-bottom: 0;
    border-left: 2px solid transparent;
    padding: 6px 0 6px 12px;
    margin-left: -14px;
    min-height: 40px;
  }
  .deck[aria-pressed="true"] { border-left-color: currentColor; }
  .deck-name { font-size: 24px; }
  .upload-link { position: static; margin-top: auto; }
}

/* ---------- 牌桌與卡片 ---------- */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
  min-width: 0;
}
.table {
  --card-h: min(62svh, 760px);
  display: grid;
  place-items: center;
  width: 100%;
  min-height: var(--card-h);
  perspective: 1800px;
}
@media (min-width: 900px) {
  .stage { padding: 40px 40px 32px; }
  .table { --card-h: min(74svh, 860px); }
}

.card {
  display: block;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  border-radius: 8px;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
}
.card-inner {
  position: relative;
  display: block;
  transform-style: preserve-3d;
  transition: transform var(--flip-in) cubic-bezier(.2, .7, .3, 1);
}
.card.is-flipped .card-inner {
  transform: rotateY(180deg);
  transition-duration: var(--flip-out);
  transition-timing-function: cubic-bezier(.5, 0, .8, .4);
}
.face {
  display: block;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 8px;
  background: var(--paper);
  padding: 9px;
  box-shadow:
    0 1px 0 color-mix(in oklab, var(--ink) 10%, transparent),
    0 24px 48px -20px color-mix(in oklab, var(--ambient), #000 55%);
}
.front img {
  display: block;
  max-width: min(100%, calc(100vw - 50px));
  max-height: calc(var(--card-h) - 18px);
  width: auto;
  height: auto;
  border-radius: 3px;
  background: color-mix(in oklab, var(--ambient) 30%, var(--paper));
}
.back {
  position: absolute;
  inset: 0;
  transform: rotateY(180deg);
  overflow: hidden;
  display: grid;
  place-items: center;
}
/* 沒有 back.jpg 的分類:紙面加細斜紋,中間印分類名 */
.back::before {
  content: '';
  position: absolute;
  inset: 9px;
  border-radius: 3px;
  border: 1px solid color-mix(in oklab, #1f1e1c 35%, transparent);
  background:
    repeating-linear-gradient(45deg, color-mix(in oklab, #1f1e1c 9%, transparent) 0 1px, transparent 1px 7px),
    repeating-linear-gradient(-45deg, color-mix(in oklab, #1f1e1c 9%, transparent) 0 1px, transparent 1px 7px),
    color-mix(in oklab, var(--ambient) 18%, var(--paper));
}
.back.has-image::before {
  background: var(--back-img) center / cover no-repeat;
  border: 0;
}
.back-name {
  position: relative;
  padding: 6px 14px;
  background: var(--paper);
  color: #1f1e1c;
  font: 500 26px/1 var(--serif);
  font-optical-sizing: auto;
}
.back.has-image .back-name { display: none; }

.empty { text-align: center; }
.empty p { margin: 0 0 8px; font-size: 17px; }
.empty a { color: var(--ink); text-underline-offset: 4px; }

/* ---------- 控制列 ---------- */
.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 520px;
}
.meta {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-height: 30px;
}
.meta-deck { font: 400 24px/1.2 var(--serif); font-optical-sizing: auto; }
.meta-left { font-size: 13px; color: var(--mute); font-variant-numeric: tabular-nums; }
.buttons { display: flex; gap: 8px; justify-content: center; width: 100%; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 20px;
  border-radius: 10px;
  font: 500 15px/1 var(--sans);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  border: 1px solid var(--rule);
  background: transparent;
  white-space: nowrap;
}
.btn:hover { border-color: color-mix(in oklab, var(--ink) 40%, transparent); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary {
  flex: 1 1 auto;
  max-width: 240px;
  background: var(--ink);
  color: var(--base);
  border-color: var(--ink);
}
.btn.primary:active { transform: translateY(1px); }
.hint { margin: 0; font-size: 12px; color: var(--mute); display: none; }
@media (hover: hover) and (pointer: fine) { .hint { display: block; } }

.status { margin: 0; min-height: 1.6em; font-size: 13px; color: var(--mute); text-align: center; }
.status.is-error { color: var(--danger); }

/* 減少動態:不翻牌,改成短淡入 */
@media (prefers-reduced-motion: reduce) {
  body { transition: none; }
  .card-inner, .card.is-flipped .card-inner { transform: none; transition: opacity 120ms linear; }
  .card.is-flipped .card-inner { opacity: 0; }
  .back { display: none; }
}
