:root {
  color-scheme: light;
  --paper: #f4f0e7;
  --ink: #273d34;
  --muted: #74796e;
  --pine: #294c3e;
  --pine-deep: #203d32;
  --gold: #bda575;
  --line: #dcdccf;
  --error: #864b31;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  font-synthesis: none;
}
* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); overscroll-behavior-x: none; }
body { margin: 0; color: var(--ink); background: radial-gradient(ellipse at 50% 35%, #fbf8f1 0, var(--paper) 72%); min-width: 280px; }
button, input { font: inherit; }
button { color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:disabled { cursor: default; }
button:focus-visible, summary:focus-visible { outline: 3px solid var(--gold); outline-offset: 5px; }
button, .play-area { -webkit-user-select: none; user-select: none; }
button svg, .deck-meta svg, .storage-title svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
p, h1, h2 { margin: 0; }
[hidden] { display: none !important; }
.svg-library { width: 0; height: 0; position: absolute; overflow: hidden; }
.app {
  min-height: 100vh; min-height: 100dvh;
  width: min(100%, 820px); margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  display: flex; flex-direction: column;
}
.app-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-shrink: 0; }
.brand { display: flex; gap: 13px; align-items: center; }
.brand-mark { width: 38px; height: 44px; fill: none; stroke: var(--pine); stroke-width: 1.2; stroke-linecap: round; stroke-linejoin: round; }
.eyebrow { text-transform: uppercase; letter-spacing: .17em; font-size: 10px; line-height: 1.5; font-weight: 600; }
h1 { font-family: Georgia, "Times New Roman", serif; font-weight: 400; font-size: 35px; line-height: 1.12; letter-spacing: -.055em; }
.icon-button { display: grid; place-items: center; flex-shrink: 0; width: 46px; height: 46px; border: 1px solid var(--line); border-radius: 50%; background: transparent; }
.icon-button:hover { background: #eae8dd; }
.menu-button svg { fill: currentColor; stroke: none; }
.play-area { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 0; padding: 42px 0 32px; touch-action: pan-y pinch-zoom; }
.deck-top { width: 100%; max-width: 674px; margin-bottom: 24px; }
.deck-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 17px; }
.deck-heading .eyebrow { color: var(--muted); }
.cycle-label { font-family: Georgia, "Times New Roman", serif; font-size: 22px; letter-spacing: -.035em; margin-top: 4px; }
.counter { display: flex; align-items: baseline; gap: 8px; font-variant-numeric: tabular-nums; }
#revealedCount { font-size: 34px; letter-spacing: -.07em; font-weight: 400; line-height: 1; }
.counter-divider { color: #b8bcae; font-size: 22px; font-weight: 300; }
.counter-total { color: var(--muted); font-size: 17px; }
.progress { display: grid; grid-template-columns: repeat(13, minmax(0, 1fr)); gap: 5px; }
.progress span { height: 3px; border-radius: 4px; background: #dcded1; transition: background-color 120ms ease; }
.progress span.done { background: var(--pine); }
.progress span.current { background: var(--gold); }
.card-stage { display: block; width: 100%; max-width: 674px; aspect-ratio: 674 / 442; position: relative; border: 0; background: transparent; padding: 0; border-radius: 12px; isolation: isolate; -webkit-touch-callout: none; }
.card-stage::before, .card-stage::after { content: ""; display: block; position: absolute; inset: 0; border: 1px solid #cfcebb; border-radius: 12px; background: #e8e6d7; z-index: -1; }
.card-stage::before { transform: translateY(8px) scale(.956, 1); }
.card-stage::after { transform: translateY(4px) scale(.98, 1); background: #f0efe5; }
.card-stage.last-card::before, .card-stage.last-card::after { visibility: hidden; }
.card-surface { display: block; width: 100%; height: 100%; overflow: hidden; position: relative; border-radius: 11px; background: #fcfaf5; box-shadow: 0 16px 30px -18px #29352966, 0 2px 5px #22332617; transform-origin: 50% 50%; }
.card-image { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; -webkit-touch-callout: none; }
.card-back { display: flex; width: 100%; height: 100%; align-items: center; justify-content: center; flex-direction: column; gap: 0; position: relative; color: #edebd8;
  background-color: var(--pine-deep);
  background-image: repeating-linear-gradient(30deg, transparent, transparent 31px, #bdac780b 32px, transparent 33px), repeating-linear-gradient(150deg, transparent, transparent 31px, #bdac780b 32px, transparent 33px);
}
.back-border { position: absolute; inset: 12px; border: 1px solid #c4b08066; border-radius: 4px; pointer-events: none; }
.back-border::after { content: ""; position: absolute; inset: 4px; border: 1px solid #c4b08022; border-radius: 2px; }
.back-kicker { text-transform: uppercase; letter-spacing: .28em; font-size: clamp(8px, 2.25vw, 12px); margin-bottom: 9px; }
.back-emblem { width: 42px; height: 42px; margin-bottom: 8px; display: block; }
.back-emblem svg { width: 100%; height: 100%; fill: none; stroke: var(--gold); stroke-width: 1.1; }
.back-title { font-family: Georgia, "Times New Roman", serif; font-size: clamp(32px, 9vw, 60px); line-height: 1; letter-spacing: -.045em; }
.back-rule { width: 28px; height: 1px; background: #c4b080a6; margin: 13px 0 10px; }
.back-caption { color: #d0d4be; font-family: Georgia, "Times New Roman", serif; font-style: italic; font-size: clamp(10px, 2.7vw, 15px); }
.card-error { padding: 20px; text-align: center; display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%; gap: 10px; background: #ede7d9; font-size: 13px; }
.card-error strong { font-family: Georgia, "Times New Roman", serif; font-size: 25px; font-weight: 400; }
.deck-meta { display: flex; align-items: center; justify-content: center; gap: 13px; font-size: 12px; color: var(--muted); margin-top: 25px; }
.deck-meta > span { display: flex; align-items: center; gap: 6px; }
.deck-meta svg { width: 15px; height: 15px; stroke-width: 1.5; }
.meta-dot { color: #adb3a5; }
.gesture-hint { font-size: 11px; color: var(--muted); margin-top: 14px; text-align: center; line-height: 1.5; }
.app-footer { flex-shrink: 0; width: 100%; max-width: 674px; align-self: center; }
.control-row { display: flex; gap: 10px; }
.primary-button { display: flex; align-items: center; justify-content: center; gap: 16px; background: var(--pine); border: 1px solid var(--pine); color: #fffdf5; border-radius: 12px; min-height: 54px; padding: 14px 18px; font-size: 14px; font-weight: 500; }
.primary-button:hover { background: var(--pine-deep); }
.primary-button:active { transform: scale(.985); }
.primary-button:disabled { opacity: .65; }
.next-button { flex: 1; justify-content: space-between; }
.undo-button { display: flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid #ced2c3; background: #f8f6ee; border-radius: 12px; min-width: 94px; min-height: 54px; padding: 12px; font-size: 12px; }
.undo-button:disabled { opacity: .4; }
.undo-button:not(:disabled):active { background: #e7e8dc; }
.undo-button svg { width: 19px; height: 19px; }
.footer-status { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 10px; color: var(--muted); padding-top: 11px; }
.save-status { display: flex; align-items: center; gap: 6px; line-height: 1.4; }
.status-dot { width: 5px; height: 5px; border-radius: 50%; background: #6c8667; flex-shrink: 0; }
.save-status.error { color: var(--error); }
.save-status.error .status-dot { background: var(--error); }
.offline-status { border: 0; background: transparent; font-size: 10px; color: inherit; padding: 10px 0 10px 10px; min-height: 44px; text-align: right; }
.notice { font-size: 12px; line-height: 1.5; border: 1px solid #d8c6a7; border-radius: 10px; background: #efe5d4; padding: 10px 12px; margin-bottom: 12px; color: #695338; }
.notice.error { color: #763923; border-color: #d9b19a; background: #f4e3d8; }
.toast { position: fixed; left: 50%; bottom: max(108px, calc(env(safe-area-inset-bottom) + 102px)); transform: translateX(-50%); width: max-content; max-width: calc(100vw - 40px); background: #21392fed; color: #fbf9ed; padding: 12px 17px; border-radius: 12px; box-shadow: 0 4px 22px #152d2326; font-size: 12px; line-height: 1.5; text-align: center; pointer-events: none; z-index: 30; }
dialog { color: var(--ink); background: #faf7ef; border: 1px solid #deddd0; box-shadow: 0 30px 90px #122b3252; padding: 27px; }
dialog::backdrop { background: #13251d70; backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.sheet { width: min(100% - 24px, 500px); max-height: min(90vh, 820px); max-height: min(90dvh, 820px); border-radius: 23px; overscroll-behavior: contain; }
.sheet-handle { width: 34px; height: 4px; background: #dadcce; margin: -13px auto 24px; border-radius: 4px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 24px; }
h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 400; font-size: 29px; letter-spacing: -.04em; line-height: 1.15; }
.dialog-heading .eyebrow { font-size: 8px; color: var(--muted); margin-bottom: 7px; }
.dialog-heading .icon-button { width: 44px; height: 44px; }
.storage-card { padding: 15px; border: 1px solid #d4ddcc; background: #eaf0e4; border-radius: 12px; }
.storage-title { display: flex; gap: 7px; align-items: center; font-size: 13px; font-weight: 600; }
.storage-title svg { width: 17px; height: 17px; }
.storage-details { font-size: 11px; margin: 12px 0 0; color: #657460; line-height: 1.7; }
.storage-details > div { display: flex; justify-content: space-between; gap: 10px; }
.storage-details dd { margin: 0; text-align: right; }
.menu-actions { margin: 18px 0; }
.menu-row { display: flex; width: 100%; align-items: center; gap: 13px; min-height: 66px; padding: 12px 3px; text-align: left; border: none; border-bottom: 1px solid #e4e3d8; background: transparent; }
.menu-row > span:nth-child(2) { flex: 1; }
.menu-row > span:last-child { font-size: 20px; color: var(--muted); }
.menu-row strong { font-size: 13px; font-weight: 500; display: block; }
.menu-row small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; line-height: 1.45; }
.menu-row:disabled { opacity: .4; }
.help { border-bottom: 1px solid #e4e3d8; padding-bottom: 14px; }
.help summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; font-size: 12px; gap: 6px; }
.help summary::before { content: '+'; font-size: 18px; margin-right: 4px; }
.help[open] summary::before { content: '−'; }
.help p { font-size: 12px; line-height: 1.75; margin: 0 0 12px; color: #606d5b; }
.help code { font-size: 11px; background: #eeece1; padding: 1px 3px; border-radius: 3px; }
.privacy-note { font-size: 10px; line-height: 1.75; color: var(--muted); margin-top: 17px; }
.app-note { font-size: 9px; line-height: 1.75; color: #848777; text-align: center; margin-top: 20px; }
.confirm-dialog { width: min(calc(100% - 40px), 380px); border-radius: 22px; text-align: center; padding: 28px 24px 18px; }
.confirm-icon { display: grid; place-items: center; width: 56px; height: 56px; background: #e8edde; border-radius: 50%; margin: 0 auto 20px; }
.confirm-icon svg { width: 25px; height: 25px; fill: none; stroke: var(--pine); stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.confirm-dialog .eyebrow { font-size: 9px; color: var(--muted); margin-bottom: 7px; }
.confirm-dialog h2 { font-size: 32px; margin-bottom: 14px; }
.confirm-dialog > p:not(.eyebrow) { font-size: 13px; line-height: 1.75; color: #687160; }
.confirm-actions { display: flex; flex-direction: column; margin-top: 23px; gap: 5px; }
.secondary-button { min-height: 48px; border: 0; border-radius: 10px; background: transparent; padding: 13px; font-size: 13px; }
.secondary-button:hover { background: #f0eee3; }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; background: var(--paper); z-index: 100; padding: 40px; text-align: center; }
.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; }
@media (min-width: 600px) and (min-height: 600px) {
  .app { padding-top: 34px; padding-bottom: 24px; }
  .play-area { padding: 38px 18px 35px; }
  .app-footer { width: calc(100% - 36px); }
  .back-emblem { width: 58px; height: 58px; margin-bottom: 12px; }
  .back-kicker { margin-bottom: 18px; }
  .back-rule { margin: 18px 0 15px; }
}
@media (max-width: 360px) {
  .app { padding-left: 17px; padding-right: 17px; }
  .undo-button { min-width: 53px; }
  .undo-button span { display: none; }
  .deck-meta { gap: 9px; font-size: 11px; }
  .back-emblem { width: 33px; height: 33px; margin-bottom: 5px; }
  .back-kicker { margin-bottom: 5px; }
  .back-rule { margin: 8px 0; }
}
@media (max-height: 710px) and (orientation: portrait) {
  .play-area { padding-top: 27px; padding-bottom: 22px; }
  .deck-top { margin-bottom: 17px; }
  .deck-heading { margin-bottom: 11px; }
  .gesture-hint { margin-top: 10px; }
}
@media (orientation: landscape) and (max-height: 540px) {
  .app { width: min(100%, 1120px); display: grid; grid-template-columns: minmax(0, 1fr) 174px; grid-template-rows: auto 1fr; column-gap: 26px; min-height: 100dvh; padding: max(12px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); }
  .app-header { grid-column: 2; grid-row: 1; gap: 5px; align-self: start; }
  .brand { gap: 0; }
  .brand-mark { display: none; }
  .brand .eyebrow { font-size: 8px; letter-spacing: .13em; }
  h1 { font-size: 29px; }
  .menu-button { width: 44px; height: 44px; }
  .play-area { grid-column: 1; grid-row: 1 / 3; min-width: 0; padding: 0; }
  .deck-top { max-width: min(100%, calc((100dvh - 102px) * 1.525)); margin-bottom: 10px; }
  .deck-heading { margin-bottom: 7px; }
  .deck-heading .eyebrow { display: none; }
  .cycle-label { font-size: 15px; margin: 0; }
  #revealedCount { font-size: 22px; }
  .counter-divider, .counter-total { font-size: 13px; }
  .progress span { height: 2px; }
  .card-stage { max-width: min(100%, calc((100dvh - 102px) * 1.525)); }
  .deck-meta { margin-top: 13px; font-size: 10px; }
  .deck-meta svg { width: 12px; height: 12px; }
  .gesture-hint { display: none; }
  .back-title { font-size: 40px; }
  .back-kicker { font-size: 9px; margin-bottom: 9px; }
  .back-caption { font-size: 12px; }
  .back-emblem { width: 40px; height: 40px; }
  .app-footer { grid-column: 2; grid-row: 2; align-self: end; width: 100%; }
  .control-row { flex-direction: column-reverse; gap: 8px; }
  .primary-button { font-size: 12px; padding: 12px; min-height: 49px; gap: 6px; }
  .next-button svg { width: 17px; height: 17px; }
  .undo-button { min-height: 44px; }
  .footer-status { flex-direction: column; gap: 0; align-items: flex-start; padding-top: 10px; font-size: 9px; }
  .offline-status { padding: 8px 0; min-height: 32px; }
  .notice { font-size: 10px; padding: 7px; margin-top: 12px; }
  .toast { bottom: 15px; max-width: 60vw; }
  .sheet { max-height: 94dvh; }
  .confirm-dialog { max-height: 94dvh; padding: 18px 24px 12px; }
  .confirm-icon { display: none; }
  .confirm-actions { margin-top: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .001ms !important; animation-duration: .001ms !important; }
  .primary-button:active { transform: none; }
}

@media (max-height: 620px) and (orientation: portrait) {
  .app { padding-top: max(16px, env(safe-area-inset-top)); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  h1 { font-size: 30px; }
  .play-area { padding-top: 18px; padding-bottom: 14px; }
  .deck-heading { margin-bottom: 9px; }
  .deck-meta { margin-top: 19px; }
}
@media (min-width: 600px) and (min-height: 600px) and (max-height: 900px) {
  .app { padding-top: 24px; padding-bottom: 16px; }
  .play-area { padding-top: 16px; padding-bottom: 16px; }
  .deck-top { margin-bottom: 16px; }
  .deck-top, .card-stage, .app-footer { max-width: min(674px, calc((100dvh - 380px) * 1.525)); }
  .deck-meta { margin-top: 18px; }
  .gesture-hint { margin-top: 10px; }
}

/* Minimal card-first layout: maximize card area, remove non-essential chrome. */
:root {
  --card-ratio: 1.5248868778;
  --edge-gap: clamp(8px, 2.5vw, 16px);
  --menu-size: 52px;
  --control-bg: rgba(248, 246, 238, 0.96);
}

body {
  background: #dfe4ec;
}

.app {
  width: 100%;
  max-width: none;
  padding: var(--edge-gap);
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
}

.app-header {
  position: fixed;
  top: max(var(--edge-gap), env(safe-area-inset-top));
  right: max(var(--edge-gap), env(safe-area-inset-right));
  z-index: 20;
  display: block;
}

.brand,
.deck-top,
.deck-meta,
.gesture-hint,
.footer-status {
  display: none !important;
}

.menu-button {
  width: var(--menu-size);
  height: var(--menu-size);
  background: rgba(244, 240, 231, 0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 10px 24px rgba(29, 43, 37, 0.08);
}

.play-area {
  min-height: calc(100vh - (var(--edge-gap) * 2));
  min-height: calc(100dvh - (var(--edge-gap) * 2));
  padding: 0;
  display: grid;
  place-items: center;
}

.card-stage {
  max-width: none;
  width: min(
    calc(100vw - (var(--edge-gap) * 2) - env(safe-area-inset-left) - env(safe-area-inset-right)),
    calc((100dvh - 148px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * var(--card-ratio))
  );
}

.card-stage::before { transform: translateY(7px) scale(.972, 1); }
.card-stage::after { transform: translateY(3px) scale(.986, 1); }
.card-surface { box-shadow: 0 14px 34px -18px #29352966, 0 3px 8px #22332620; }

.app-footer {
  position: fixed;
  left: max(var(--edge-gap), env(safe-area-inset-left));
  right: max(var(--edge-gap), env(safe-area-inset-right));
  bottom: max(var(--edge-gap), env(safe-area-inset-bottom));
  z-index: 15;
  width: auto;
  max-width: none;
  pointer-events: none;
}

.notice {
  margin: 0 0 10px auto;
  max-width: min(420px, 100%);
  pointer-events: auto;
}

.control-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  pointer-events: auto;
}

.undo-button,
.next-button {
  min-height: 50px;
  border-radius: 14px;
  background: var(--control-bg);
  box-shadow: 0 10px 24px rgba(29, 43, 37, 0.08);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.undo-button {
  min-width: 126px;
  font-size: 14px;
}

.next-button {
  flex: 0 1 280px;
}

.toast {
  bottom: max(84px, calc(env(safe-area-inset-bottom) + 76px));
}

@media (orientation: portrait) {
  .app {
    padding-top: max(var(--edge-gap), env(safe-area-inset-top));
    padding-bottom: max(var(--edge-gap), env(safe-area-inset-bottom));
  }

  .card-stage {
    width: min(
      calc(100vw - (var(--edge-gap) * 2) - env(safe-area-inset-left) - env(safe-area-inset-right)),
      calc((100dvh - 138px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * var(--card-ratio))
    );
  }

  .control-row {
    justify-content: stretch;
  }

  .undo-button {
    flex: 0 0 auto;
  }

  .next-button {
    flex: 1 1 auto;
  }
}

@media (orientation: landscape) {
  .play-area {
    min-height: calc(100vh - (var(--edge-gap) * 2));
    min-height: calc(100dvh - (var(--edge-gap) * 2));
  }

  .card-stage {
    width: min(
      calc(100vw - 136px - (var(--edge-gap) * 2) - env(safe-area-inset-left) - env(safe-area-inset-right)),
      calc((100dvh - (var(--edge-gap) * 2) - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * var(--card-ratio))
    );
  }

  .app-footer {
    left: auto;
    right: max(var(--edge-gap), env(safe-area-inset-right));
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    width: 108px;
  }

  .notice {
    margin: 0 0 10px;
    max-width: 100%;
    font-size: 10px;
    padding: 8px;
  }

  .control-row {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .undo-button,
  .next-button {
    min-height: 52px;
    width: 100%;
    padding: 12px 14px;
  }

  .undo-button {
    min-width: 0;
    font-size: 12px;
  }

  .next-button {
    flex: 0 0 auto;
    font-size: 13px;
    gap: 10px;
  }

  .toast {
    bottom: 18px;
    left: 50%;
    max-width: min(56vw, 420px);
  }
}

@media (max-width: 420px) {
  .undo-button {
    min-width: 104px;
    padding-inline: 14px;
  }

  .primary-button,
  .undo-button {
    min-height: 48px;
  }
}

@media (max-height: 430px) and (orientation: landscape) {
  :root {
    --menu-size: 48px;
  }

  .card-stage {
    width: min(
      calc(100vw - 126px - (var(--edge-gap) * 2) - env(safe-area-inset-left) - env(safe-area-inset-right)),
      calc((100dvh - (var(--edge-gap) * 2) - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * var(--card-ratio))
    );
  }

  .app-footer {
    width: 98px;
  }

  .undo-button,
  .next-button {
    min-height: 46px;
    padding: 10px 12px;
  }

  .undo-button span,
  .next-button span {
    font-size: 11px;
  }
}
