:root {
  --bg: #f4eadc;
  --bg-2: #efe0cb;
  --paper: rgba(255, 248, 238, 0.88);
  --paper-solid: #fff7ec;
  --ink: #2b2118;
  --muted: #7b6a58;
  --brand: #7b5b3d;
  --brand-dark: #4f3521;
  --line: rgba(79, 53, 33, 0.16);
  --shadow: 0 18px 50px rgba(74, 47, 26, 0.18);
  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 8%, rgba(255, 255, 255, 0.52), transparent 28%),
    radial-gradient(circle at 88% 18%, rgba(199, 151, 97, 0.18), transparent 35%),
    linear-gradient(180deg, #ead7bd 0%, #f5eadb 42%, #e9d2b6 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.48;
  background:
    linear-gradient(90deg, rgba(95, 65, 40, 0.08) 1px, transparent 1px),
    linear-gradient(0deg, rgba(95, 65, 40, 0.05) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(123, 91, 61, 0.36);
  outline-offset: 3px;
}

.app-shell {
  width: min(100%, 480px);
  margin: 0 auto;
  padding: 18px 16px calc(28px + var(--safe-bottom));
}

.hero-card,
.panel {
  border: 1px solid var(--line);
  background: var(--paper);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.hero-card {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  min-height: 170px;
  padding: 24px;
  border-radius: 34px;
  background:
    linear-gradient(135deg, rgba(255, 249, 239, 0.94), rgba(229, 204, 173, 0.7)),
    url("assets/card-example.png");
  background-size: cover;
  background-position: center;
  position: relative;
  overflow: hidden;
}

.hero-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(255, 247, 236, 0.92), rgba(255, 247, 236, 0.62), rgba(255, 247, 236, 0.22));
}

.hero-copy,
.ghost-button,
.hero-actions {
  position: relative;
  z-index: 1;
}

.hero-copy {
  min-width: 0;
  flex: 1 1 auto;
}

.hero-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  flex: 0 0 auto;
}

.lang-switch {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: rgba(255, 250, 242, 0.7);
  box-shadow: inset 0 0 0 1px rgba(79, 53, 33, 0.16);
}

.lang-btn {
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  color: var(--brand-dark);
  background: transparent;
  font-size: 0.74rem;
  font-weight: 800;
  white-space: nowrap;
  transition: background 160ms ease, color 160ms ease;
}

.lang-btn.is-active {
  color: #fffaf2;
  background: linear-gradient(135deg, #8b6340, #4f3521);
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--brand);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(1.9rem, 8vw, 3.05rem);
  line-height: 1.05;
  letter-spacing: -0.06em;
  overflow-wrap: break-word;
  word-break: break-word;
  hyphens: auto;
}

h2 {
  margin-bottom: 0;
  font-size: 1.22rem;
  line-height: 1.2;
}

.subtitle {
  max-width: 250px;
  margin-bottom: 0;
  color: var(--muted);
  font-weight: 600;
  line-height: 1.55;
}

.panel {
  margin-top: 16px;
  padding: 18px;
  border-radius: var(--radius-lg);
}

.section-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-count,
.state-pill {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--brand-dark);
  background: rgba(124, 91, 60, 0.1);
  font-size: 0.78rem;
  font-weight: 800;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.category-button {
  min-height: 55px;
  padding: 10px 8px;
  border-radius: 18px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.5);
  box-shadow: inset 0 0 0 1px var(--line);
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.category-button strong {
  display: block;
  font-size: 0.96rem;
}

.category-button small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
}

.category-button.is-active {
  color: #fffaf2;
  background: linear-gradient(135deg, #7f5a39, #4f3521);
  box-shadow: 0 14px 28px rgba(79, 53, 33, 0.24);
  transform: translateY(-1px);
}

.category-button.is-active small {
  color: rgba(255, 250, 242, 0.78);
}

.theme-block {
  margin-top: 16px;
}

.theme-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.theme-button {
  min-height: 36px;
  padding: 0 13px;
  border-radius: 999px;
  color: var(--brand-dark);
  background: rgba(255, 255, 255, 0.5);
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 0.84rem;
  font-weight: 800;
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.theme-button.is-active {
  color: #fffaf2;
  background: linear-gradient(135deg, #7f5a39, #4f3521);
  box-shadow: 0 10px 22px rgba(79, 53, 33, 0.22);
  transform: translateY(-1px);
}

.theme-button:active {
  transform: scale(0.98);
}

.small-button.ghost {
  background: transparent;
  box-shadow: inset 0 0 0 1px rgba(79, 53, 33, 0.2);
}

.timer-box {
  margin-top: 16px;
  padding: 16px;
  border-radius: var(--radius-md);
  text-align: center;
  background: rgba(255, 255, 255, 0.46);
  box-shadow: inset 0 0 0 1px var(--line);
  transition: background 200ms ease, box-shadow 200ms ease;
}

.timer-box.is-running {
  background: rgba(124, 91, 60, 0.12);
  box-shadow: inset 0 0 0 1px rgba(79, 53, 33, 0.3);
}

.timer-box.is-done {
  background: rgba(176, 74, 56, 0.14);
  box-shadow: inset 0 0 0 1px rgba(176, 74, 56, 0.4);
}

.timer-display {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 2.6rem;
  font-weight: 950;
  letter-spacing: 0.04em;
  line-height: 1.1;
  color: var(--brand-dark);
}

.timer-box.is-done .timer-display {
  color: #a8442f;
}

.timer-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.timer-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.5;
}

.question-card.is-function .card-content {
  padding-top: 16px;
}

.question-card.is-function .card-number {
  color: #a8442f;
}

.question-card.is-function .card-level {
  background: #a8442f;
}

.history-clear {
  margin-top: 12px;
}

.deck-zone {
  display: grid;
  place-items: center;
  min-height: 188px;
  margin: 6px 0 18px;
  border-radius: 26px;
  background:
    radial-gradient(circle at center, rgba(255, 255, 255, 0.7), transparent 46%),
    linear-gradient(135deg, rgba(139, 103, 65, 0.14), rgba(255, 255, 255, 0.14));
}

.deck {
  position: relative;
  width: 132px;
  height: 168px;
  transform-style: preserve-3d;
}

.deck-card {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  border: 1px solid rgba(79, 53, 33, 0.18);
  background:
    linear-gradient(135deg, rgba(255, 247, 236, 0.88), rgba(214, 178, 132, 0.84)),
    radial-gradient(circle at 70% 18%, rgba(255,255,255,0.62), transparent 30%);
  box-shadow: 0 18px 42px rgba(70, 47, 31, 0.22);
}

.deck-card::before {
  content: "";
  position: absolute;
  inset: 13px;
  border-radius: 15px;
  border: 1px dashed rgba(79, 53, 33, 0.28);
}

.deck-card::after {
  content: "心";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(79, 53, 33, 0.42);
  font-size: 2.6rem;
  font-weight: 900;
}

.deck-card-1 {
  transform: rotate(2deg);
}

.deck-card-2 {
  transform: rotate(-7deg) translate(-8px, 5px);
}

.deck-card-3 {
  transform: rotate(7deg) translate(8px, 4px);
}

.deck .fan {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 2;
}

.deck .fan span {
  position: absolute;
  width: 104px;
  height: 148px;
  border-radius: 14px;
  border: 1px solid rgba(79, 53, 33, 0.18);
  background:
    linear-gradient(135deg, rgba(255, 247, 236, 0.92), rgba(214, 178, 132, 0.92)),
    radial-gradient(circle at 70% 18%, rgba(255, 255, 255, 0.58), transparent 30%);
  box-shadow: 0 12px 26px rgba(70, 47, 31, 0.22);
  opacity: 0;
}

.deck.is-fanning .deck-card {
  opacity: 0;
  transition: opacity 120ms ease;
}

.deck.is-fanning .fan span {
  animation: fanSpread 1100ms ease forwards;
}

.deck.is-fanning .fan span:nth-child(1) { animation-delay: 0ms; }
.deck.is-fanning .fan span:nth-child(2) { animation-delay: 55ms; }
.deck.is-fanning .fan span:nth-child(3) { animation-delay: 110ms; }
.deck.is-fanning .fan span:nth-child(4) { animation-delay: 165ms; }
.deck.is-fanning .fan span:nth-child(5) { animation-delay: 220ms; }
.deck.is-fanning .fan span:nth-child(6) { animation-delay: 275ms; }
.deck.is-fanning .fan span:nth-child(7) { animation-delay: 330ms; }

@keyframes fanSpread {
  0%   { opacity: 0; transform: rotate(0deg) translateY(0); }
  30%  { opacity: 1; }
  58%  { opacity: 1; }
  100% { opacity: 0; transform: var(--fanT) translateY(-6px); }
}

.deck.is-shuffling .deck-card-1 {
  animation: shuffleA 860ms ease-in-out infinite;
}

.deck.is-shuffling .deck-card-2 {
  animation: shuffleB 860ms ease-in-out infinite;
}

.deck.is-shuffling .deck-card-3 {
  animation: shuffleC 860ms ease-in-out infinite;
}

@keyframes shuffleA {
  0%, 100% { transform: rotate(2deg) translate(0, 0); }
  50% { transform: rotate(12deg) translate(18px, -8px); }
}

@keyframes shuffleB {
  0%, 100% { transform: rotate(-7deg) translate(-8px, 5px); }
  50% { transform: rotate(-15deg) translate(-24px, 3px); }
}

@keyframes shuffleC {
  0%, 100% { transform: rotate(7deg) translate(8px, 4px); }
  50% { transform: rotate(0deg) translate(0, -18px); }
}

.primary-button,
.secondary-button,
.ghost-button,
.small-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-weight: 900;
  transition: transform 160ms ease, opacity 160ms ease, box-shadow 160ms ease;
}

.primary-button {
  width: 100%;
  min-height: 56px;
  color: #fffaf2;
  background: linear-gradient(135deg, #8b6340, #4f3521);
  box-shadow: 0 16px 34px rgba(79, 53, 33, 0.27);
  font-size: 1.02rem;
}

.secondary-button {
  min-height: 48px;
  padding: 0 12px;
  color: var(--brand-dark);
  background: rgba(255, 255, 255, 0.62);
  box-shadow: inset 0 0 0 1px var(--line);
}

.ghost-button,
.small-button {
  min-height: 36px;
  padding: 0 13px;
  color: var(--brand-dark);
  background: rgba(255, 250, 242, 0.72);
  box-shadow: inset 0 0 0 1px rgba(79, 53, 33, 0.12);
  font-size: 0.86rem;
  white-space: nowrap;
}

.primary-button:active,
.secondary-button:active,
.ghost-button:active,
.small-button:active,
.category-button:active {
  transform: scale(0.98);
}

.hidden {
  display: none;
}

.question-card {
  perspective: 1200px;
}

.card-inner {
  overflow: hidden;
  border-radius: 26px;
  border: 1px solid rgba(79, 53, 33, 0.18);
  background:
    linear-gradient(180deg, rgba(255, 248, 238, 0.98), rgba(245, 226, 202, 0.94));
  box-shadow: 0 18px 42px rgba(70, 47, 31, 0.18);
  transform-origin: center;
}

.question-card.is-revealed .card-inner {
  animation: revealCard 520ms cubic-bezier(.2,.9,.2,1);
}

@keyframes revealCard {
  0%   { opacity: 0; transform: scale(0.62) translateY(14px); }
  60%  { opacity: 1; transform: scale(1.06) translateY(0); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.card-visual {
  width: 100%;
  aspect-ratio: 3 / 4;
  background: #dec7a7;
  overflow: hidden;
  border-radius: 22px 22px 0 0;
}

.card-visual img,
.card-visual svg {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  background: #dec7a7;
}

.card-content {
  padding: 20px 20px 23px;
  text-align: center;
}

.card-number {
  margin-bottom: 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.22rem;
  font-weight: 950;
  letter-spacing: 0.03em;
}

.card-level {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 66px;
  margin: 0 auto 14px;
  padding: 5px 12px;
  border-radius: 999px;
  color: #fffaf2;
  background: var(--brand-dark);
  font-weight: 900;
}

.card-question {
  margin-bottom: 0;
  font-size: clamp(1.24rem, 5vw, 1.65rem);
  line-height: 1.45;
  letter-spacing: -0.03em;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin-top: 14px;
}

.favorites-panel {
  margin-bottom: 8px;
}

summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-weight: 900;
  list-style: none;
}

summary::-webkit-details-marker {
  display: none;
}

summary small {
  color: var(--muted);
}

.favorite-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.favorite-item {
  display: grid;
  gap: 4px;
  width: 100%;
  text-align: left;
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.52);
  box-shadow: inset 0 0 0 1px var(--line);
}

.favorite-item strong {
  font-size: 0.86rem;
}

.favorite-item p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.9rem;
}

.empty-message {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.feedback-form {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.star-input {
  display: flex;
  gap: 4px;
}

.star {
  padding: 2px 4px;
  background: none;
  color: rgba(79, 53, 33, 0.28);
  font-size: 1.7rem;
  line-height: 1;
  transition: transform 120ms ease, color 120ms ease;
}

.star.is-on {
  color: #e0a93c;
}

.star:active {
  transform: scale(0.88);
}

.field {
  width: 100%;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.62);
  box-shadow: inset 0 0 0 1px var(--line);
  font: inherit;
  resize: vertical;
}

.field::placeholder {
  color: rgba(123, 106, 88, 0.7);
}

.field:focus-visible {
  outline: 3px solid rgba(123, 91, 61, 0.32);
  outline-offset: 1px;
}

.message-list {
  display: grid;
  gap: 10px;
}

.message-item {
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.52);
  box-shadow: inset 0 0 0 1px var(--line);
}

.message-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.message-head strong {
  font-size: 0.92rem;
}

.message-stars {
  flex: 0 0 auto;
  color: #e0a93c;
  font-size: 0.92rem;
  letter-spacing: 1px;
}

.message-text {
  margin: 0 0 6px;
  color: var(--ink);
  line-height: 1.5;
  font-size: 0.92rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-time {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
}

.app-footer {
  margin-top: 22px;
  padding: 4px 6px;
  text-align: center;
}

.footer-visits {
  margin: 0 0 4px;
  color: var(--brand-dark);
  font-size: 0.9rem;
  font-weight: 800;
}

.footer-visits strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.footer-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.footer-credit {
  margin: 10px 0 0;
  text-align: right;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.6;
}

.footer-credit a {
  color: var(--brand);
  font-weight: 800;
  text-decoration: none;
  border-bottom: 1px solid rgba(123, 91, 61, 0.4);
}

.footer-credit a:active {
  opacity: 0.7;
}

.guide-lead {
  color: var(--muted);
  line-height: 1.65;
  font-weight: 600;
}

.guide-h3 {
  margin: 18px 0 8px;
  font-size: 1rem;
  color: var(--brand-dark);
}

.guide-example {
  padding-left: 1.3rem;
  color: var(--muted);
  line-height: 1.7;
}

.guide-example em {
  color: var(--ink);
  font-style: normal;
  font-weight: 800;
}

.guide-dialog {
  width: min(calc(100% - 28px), 430px);
  padding: 0;
  border: 0;
  border-radius: 26px;
  background: transparent;
}

.guide-dialog::backdrop {
  background: rgba(35, 24, 16, 0.48);
  backdrop-filter: blur(5px);
}

.dialog-card {
  position: relative;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--paper-solid);
  box-shadow: 0 28px 80px rgba(35, 24, 16, 0.32);
}

.dialog-card ol {
  padding-left: 1.3rem;
  color: var(--muted);
  line-height: 1.7;
}

.dialog-card code {
  color: var(--brand-dark);
  background: rgba(123, 91, 61, 0.09);
  border-radius: 7px;
  padding: 2px 5px;
}

.close-button {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  color: var(--brand-dark);
  background: rgba(123, 91, 61, 0.1);
  font-size: 1.25rem;
  font-weight: 900;
}

.hint {
  margin-bottom: 0;
  color: var(--brand-dark);
  font-weight: 800;
  line-height: 1.55;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  z-index: 100;
  max-width: min(420px, calc(100% - 32px));
  padding: 12px 14px;
  border-radius: 999px;
  color: #fffaf2;
  background: rgba(43, 33, 24, 0.9);
  box-shadow: 0 16px 36px rgba(43, 33, 24, 0.28);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 160ms ease, transform 160ms ease;
  font-size: 0.9rem;
  font-weight: 800;
  text-align: center;
}

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

@media (min-width: 481px) {
  .app-shell {
    padding-top: 30px;
  }
}

/* 手機首頁可讀性優化：避免主標被擠成一字一行 */
@media (max-width: 420px) {
  .app-shell {
    padding: 14px 12px calc(24px + var(--safe-bottom));
  }

  .hero-card {
    min-height: 0;
    padding: 16px;
    border-radius: 24px;
    gap: 12px;
    flex-direction: column;
    align-items: stretch;
  }

  .hero-card::before {
    background: linear-gradient(180deg, rgba(255, 247, 236, 0.94), rgba(255, 247, 236, 0.76));
  }

  .hero-actions {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
  }

  .lang-switch {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  h1 {
    margin-bottom: 6px;
    font-size: clamp(2rem, 11vw, 2.5rem);
    line-height: 1.12;
    letter-spacing: -0.03em;
    word-break: keep-all;
  }

  .subtitle {
    max-width: none;
    font-size: 0.96rem;
    line-height: 1.55;
  }

  .section-title-row {
    gap: 8px;
    flex-wrap: wrap;
  }

  .panel {
    margin-top: 12px;
    padding: 14px;
    border-radius: 22px;
  }

  .category-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .action-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .action-grid .secondary-button:last-child {
    grid-column: 1 / -1;
  }
}

/* 超小螢幕再壓縮，確保不爆版 */
@media (max-width: 360px) {
  .hero-card {
    padding: 14px;
  }

  .lang-btn {
    padding: 0 7px;
    font-size: 0.7rem;
  }

  .ghost-button,
  .small-button {
    min-height: 34px;
    padding: 0 10px;
    font-size: 0.8rem;
  }

  h1 {
    font-size: clamp(1.8rem, 10.6vw, 2.25rem);
  }

  .category-button {
    min-height: 52px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
