/* 心田消消樂 — 沿用 game.css token */

:root {
  --font-display: "Noto Serif TC", "PingFang TC", serif;
  --color-ink: #3d2e1f;
  --color-ink-soft: #6f604f;
  --color-accent: #7a4f24;
  --color-accent-dark: #5e3b18;
  --color-sage: #7a8c6d;
  --color-gold-soft: #f8e7b8;
  --color-line: rgba(61, 46, 31, 0.14);
  --radius-md: 12px;
  --radius-lg: 22px;
  --shadow-soft: 0 18px 45px rgba(61, 46, 31, 0.16);
}

[hidden] { display: none !important; }

.match-shell {
  padding: 88px 16px 40px;
  min-height: 100vh;
  background: #faf6ee;
}

.match-wrap {
  max-width: 520px;
  margin: 0 auto;
}

.match-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.match-head h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: var(--color-ink);
  margin: 0;
}

.match-eyebrow {
  display: block;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  color: var(--color-sage);
  margin-bottom: 4px;
}

.match-back {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--color-line);
  background: #fffdf7;
  color: var(--color-accent);
  font-size: 0.85rem;
  text-decoration: none;
  white-space: nowrap;
}

.match-hud {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.hud-card {
  background: #fffdf7;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  text-align: center;
  box-shadow: 0 4px 14px rgba(61, 46, 31, 0.06);
}

.hud-label {
  display: block;
  font-size: 0.72rem;
  color: var(--color-ink-soft);
  margin-bottom: 2px;
}

.hud-value {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-accent-dark);
}

.match-goals {
  background: linear-gradient(135deg, #fffdf7, #f8f2e4);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 14px;
}

.match-goals h2 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-ink-soft);
  margin: 0 0 8px;
}

.goal-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.goal-item {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(122, 140, 109, 0.12);
  font-size: 0.82rem;
  color: var(--color-ink);
  min-width: 120px;
}

.goal-item-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.goal-bar {
  width: 100%;
  height: 5px;
  border-radius: 999px;
  background: rgba(61, 46, 31, 0.1);
  overflow: hidden;
}

.goal-bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #7a8c6d, #5f8f51);
  transition: width 0.25s ease;
}

.goal-item.done {
  opacity: 0.45;
  text-decoration: line-through;
}

.goal-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.match-stage {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: linear-gradient(180deg, #b9e2f2 0%, #e7f3dd 22%, #a9d884 42%, #8bc968 68%, #7fbf5e 100%);
  box-shadow: var(--shadow-soft);
  padding: 12px;
}

.match-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 80% 60% at 50% 20%, rgba(255, 253, 247, 0.35), transparent 70%);
  opacity: 0.85;
}

@media (prefers-reduced-motion: no-preference) {
  .match-stage::after {
    content: "";
    position: absolute;
    inset: -20%;
    pointer-events: none;
    background: conic-gradient(from 0deg, transparent, rgba(255, 246, 216, 0.14), transparent, rgba(185, 226, 242, 0.12), transparent);
    animation: stage-shimmer 14s linear infinite;
  }
}

@keyframes stage-shimmer {
  to { transform: rotate(360deg); }
}

.match-stage-glow {
  position: absolute;
  inset: 10px;
  border-radius: var(--radius-md);
  pointer-events: none;
  opacity: 0;
  box-shadow: inset 0 0 0 2px rgba(255, 246, 216, 0.5), 0 0 28px rgba(255, 230, 160, 0.45);
  transition: opacity 0.2s ease;
}

.match-stage-glow.active {
  opacity: 1;
}

@media (prefers-reduced-motion: no-preference) {
  .match-stage-glow.pulse {
    animation: stage-glow-pulse 0.55s ease-out;
  }
}

@keyframes stage-glow-pulse {
  0% { opacity: 0; transform: scale(0.98); }
  35% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.01); }
}

.match-cinematic {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  overflow: hidden;
  border-radius: var(--radius-md);
}

.petal-field {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.petal {
  position: absolute;
  width: 10px;
  height: 14px;
  border-radius: 70% 30% 70% 30%;
  opacity: 0.9;
  pointer-events: none;
}

.petal-win {
  background: linear-gradient(135deg, #f8e7b8, #f2b8c6, #ffd8e8);
  box-shadow: 0 0 8px rgba(255, 230, 200, 0.45);
}

.petal-lose {
  background: linear-gradient(135deg, #c9b89a, #8a7a66);
  opacity: 0.55;
}

@media (prefers-reduced-motion: no-preference) {
  .petal-win {
    animation: petal-rise var(--dur, 1.4s) ease-out forwards;
  }
  .petal-lose {
    animation: petal-fall var(--dur, 1.2s) ease-in forwards;
  }
}

@keyframes petal-rise {
  0% { transform: translateY(20px) rotate(0deg) scale(0.6); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translateY(-120%) rotate(280deg) scale(1); opacity: 0; }
}

@keyframes petal-fall {
  0% { transform: translateY(-10%) rotate(0deg); opacity: 0.7; }
  100% { transform: translateY(130%) rotate(220deg); opacity: 0; }
}

.cinematic-flash {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.cinematic-flash.win {
  background: radial-gradient(circle at 50% 45%, rgba(255, 246, 216, 0.75), rgba(255, 253, 247, 0) 68%);
}

.cinematic-flash.lose {
  background: radial-gradient(circle at 50% 50%, rgba(61, 46, 31, 0.28), rgba(61, 46, 31, 0.05) 70%);
}

@media (prefers-reduced-motion: no-preference) {
  .cinematic-flash.show-win {
    animation: flash-win 0.9s ease-out;
  }
  .cinematic-flash.show-lose {
    animation: flash-lose 0.75s ease-out;
  }
}

@keyframes flash-win {
  0% { opacity: 0; }
  25% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes flash-lose {
  0% { opacity: 0; }
  30% { opacity: 1; }
  100% { opacity: 0; }
}

.win-bloom {
  margin-bottom: 14px;
  text-align: left;
}

.win-bloom-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(122, 140, 109, 0.15);
  overflow: hidden;
}

.win-bloom-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #a9d884, #5f8f51, #d9a23c);
}

.win-bloom-text {
  margin: 6px 0 0 !important;
  font-size: 0.8rem !important;
  color: var(--color-sage) !important;
}

@media (prefers-reduced-motion: no-preference) {
  .win-modal-card.reveal {
    animation: win-reveal 0.65s ease-out;
  }
  .lose-modal-card.reveal {
    animation: lose-reveal 0.55s ease-out;
  }
  .win-bloom-fill.grow {
    animation: bloom-grow 1s ease-out forwards;
  }
}

@keyframes win-reveal {
  0% { transform: translateY(18px) scale(0.94); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes lose-reveal {
  0% { transform: translateY(10px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

@keyframes bloom-grow {
  from { width: 0; }
  to { width: var(--bloom-target, 100%); }
}

#matchCanvas.cinematic-dim {
  filter: saturate(0.72) brightness(0.88);
  transition: filter 0.35s ease;
}

#matchCanvas.cinematic-bloom {
  filter: saturate(1.08) brightness(1.04);
  transition: filter 0.35s ease;
}

#matchCanvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  touch-action: none;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.match-combo {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 900;
  color: #fffdf7;
  text-shadow: 0 2px 12px rgba(61, 46, 31, 0.5), 0 0 24px rgba(255, 230, 160, 0.55);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.match-combo.show {
  opacity: 1;
  animation: combo-pop 0.75s ease;
}

.match-combo.combo-tier-2 { font-size: clamp(1.5rem, 5.5vw, 2.1rem); }
.match-combo.combo-tier-3 { font-size: clamp(1.7rem, 6vw, 2.35rem); color: #fff9e8; }
.match-combo.combo-tier-4 { font-size: clamp(1.9rem, 6.5vw, 2.6rem); color: #fff4c8; }
.match-combo.combo-tier-5 { font-size: clamp(2.1rem, 7vw, 2.85rem); color: #ffe89a; }

.hud-value.hud-pop {
  animation: hud-pop 0.45s ease;
}

@keyframes hud-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); color: #5f8f51; }
  100% { transform: scale(1); }
}

@keyframes combo-pop {
  0% { transform: translate(-50%, -50%) scale(0.6); opacity: 0; }
  40% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

.match-level-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  font-size: 0.82rem;
  color: var(--color-ink-soft);
}

/* ── 選關地圖 ── */
.map-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.map-progress {
  font-size: 0.82rem;
  color: var(--color-ink-soft);
}

.weekly-panel {
  background: linear-gradient(135deg, #fffdf7, #f3f8ec);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: 0 6px 20px rgba(61, 46, 31, 0.06);
}

.weekly-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.weekly-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--color-ink);
}

.weekly-sub {
  font-size: 0.72rem;
  color: var(--color-ink-soft);
}

.weekly-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.weekly-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: rgba(255, 253, 247, 0.9);
  border: 1px solid rgba(122, 140, 109, 0.2);
  font-size: 0.8rem;
}

.weekly-item.done {
  opacity: 0.55;
}

.weekly-item.done .weekly-label {
  text-decoration: line-through;
}

.weekly-count {
  font-size: 0.74rem;
  color: var(--color-accent);
  font-weight: 600;
}

.weekly-item .goal-bar {
  grid-column: 1 / -1;
}

.map-ch-bloom {
  margin: 8px 0 12px;
}

.map-ch-bloom-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(61, 46, 31, 0.08);
  overflow: hidden;
}

.map-ch-bloom-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #a9d884, #5f8f51);
}

.map-ch-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--color-ink-soft);
}

.map-chapter {
  background: linear-gradient(135deg, #fffdf7, #f8f2e4);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: 0 6px 20px rgba(61, 46, 31, 0.06);
}

.map-chapter.locked {
  opacity: 0.55;
  filter: grayscale(0.4);
}

.map-ch-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.map-ch-head h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--color-ink);
  margin: 0;
}

.map-ch-stars {
  font-size: 0.8rem;
  color: var(--color-accent);
}

.map-ch-desc {
  margin: 4px 0 12px;
  font-size: 0.8rem;
  color: var(--color-ink-soft);
}

.map-nodes {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.map-node {
  width: 58px;
  height: 58px;
  border-radius: 16px;
  border: 1px solid var(--color-line);
  background: #fffdf7;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-family: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.map-node:not(.locked):hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(61, 46, 31, 0.14);
}

.map-node.cleared {
  background: linear-gradient(135deg, #eef7e4, #fffdf7);
  border-color: rgba(95, 143, 81, 0.4);
}

.map-node.locked {
  cursor: default;
  background: rgba(61, 46, 31, 0.05);
}

.map-node-id {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--color-accent-dark);
}

.map-node-stars {
  font-size: 0.6rem;
  color: #d9a23c;
  letter-spacing: 1px;
}

.map-node-lock {
  font-size: 1.1rem;
  opacity: 0.6;
}

/* ── 師傅的一句話 ── */
.level-intro {
  margin: 0 0 12px;
  padding: 9px 14px;
  border-left: 3px solid var(--color-sage);
  background: rgba(122, 140, 109, 0.1);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-size: 0.85rem;
  color: var(--color-ink);
}

/* ── 過關知識卡 ── */
.win-reward {
  min-height: 1.2em;
  font-size: 0.9rem;
  color: #5f8f51;
  font-weight: 600;
  margin: 0 0 10px !important;
}

.win-reward a {
  color: var(--color-accent);
}

.win-card {
  position: relative;
  text-align: left;
  background: linear-gradient(135deg, #fdf8ec, #f4ecd8);
  border: 1px solid rgba(217, 162, 60, 0.35);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 16px;
}

.win-card h4 {
  font-family: var(--font-display);
  margin: 0 0 6px;
  font-size: 1rem;
  color: var(--color-accent-dark);
}

.win-card p {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.7;
  color: var(--color-ink);
}

.win-card-badge {
  position: absolute;
  top: -9px;
  right: 12px;
  padding: 2px 10px;
  border-radius: 999px;
  background: linear-gradient(135deg, #d9a23c, #b97e1e);
  color: #fffdf7;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
}

.win-card.flip-in {
  animation: card-flip 0.6s ease;
}

@keyframes card-flip {
  0% { transform: perspective(600px) rotateY(90deg); opacity: 0; }
  100% { transform: perspective(600px) rotateY(0); opacity: 1; }
}

/* ── 圖鑑 ── */
.gallery-modal-card {
  width: min(100%, 460px);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.gallery-grid {
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
  text-align: left;
}

.gallery-card {
  background: linear-gradient(135deg, #fdf8ec, #f4ecd8);
  border: 1px solid rgba(217, 162, 60, 0.3);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

.gallery-card.locked {
  background: rgba(61, 46, 31, 0.05);
  border-color: var(--color-line);
  opacity: 0.7;
}

.gallery-card h4 {
  font-family: var(--font-display);
  margin: 0 0 4px;
  font-size: 0.86rem;
  color: var(--color-accent-dark);
}

.gallery-card p {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.6;
  color: var(--color-ink-soft);
}

@media (max-width: 420px) {
  .gallery-grid { grid-template-columns: 1fr; }
}

.match-sound {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
}

.match-chip {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--color-line);
  background: #fffdf7;
  color: var(--color-ink);
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.match-chip.off {
  opacity: 0.4;
}

.match-sound-settings {
  margin-top: 8px;
  flex-wrap: wrap;
}

.sound-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--color-ink-soft);
}

.sound-field select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 22px;
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%237a4f24' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.sound-field select:disabled,
.sound-field input:disabled {
  opacity: 0.4;
}

.sound-field input[type="range"] {
  width: 110px;
  accent-color: var(--color-accent);
}

.match-note {
  margin-top: 14px;
  font-size: 0.78rem;
  color: var(--color-ink-soft);
  text-align: center;
}

/* modal（比照 game.css） */
.match-modal {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(61, 46, 31, 0.45);
  backdrop-filter: blur(4px);
}

.match-modal-card {
  position: relative;
  width: min(100%, 380px);
  background: #fffdf7;
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  text-align: center;
  box-shadow: var(--shadow-soft);
}

.match-modal-card h3 {
  font-family: var(--font-display);
  margin: 0 0 10px;
  font-size: 1.35rem;
  color: var(--color-ink);
}

.match-modal-card p {
  margin: 0 0 18px;
  color: var(--color-ink-soft);
  font-size: 0.92rem;
  line-height: 1.6;
}

.lose-gaps {
  list-style: none;
  margin: 0 0 16px;
  padding: 10px 12px;
  text-align: left;
  background: rgba(122, 140, 109, 0.1);
  border-radius: var(--radius-md);
}

.lose-gaps li {
  font-size: 0.86rem;
  color: var(--color-ink);
  padding: 4px 0;
}

.lose-gaps li + li {
  border-top: 1px dashed rgba(61, 46, 31, 0.12);
}

.tutorial-card,
.howto-card {
  text-align: left;
}

.tutorial-badge {
  display: inline-block;
  margin-bottom: 8px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(122, 140, 109, 0.18);
  color: var(--color-sage);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
}

.howto-list {
  margin: 0 0 18px;
  padding-left: 1.1rem;
  color: var(--color-ink-soft);
  font-size: 0.88rem;
  line-height: 1.7;
}

.howto-list li + li {
  margin-top: 8px;
}

.match-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.match-btn {
  padding: 10px 20px;
  border-radius: 999px;
  border: 1px solid var(--color-line);
  background: #fff;
  color: var(--color-ink);
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
}

.match-btn-primary {
  background: linear-gradient(135deg, #5f8f51, #7a4f24);
  color: #fffdf7;
  border-color: transparent;
}

.match-stars {
  font-size: 1.6rem;
  letter-spacing: 4px;
  margin-bottom: 8px;
}

@media (max-width: 400px) {
  .match-hud { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .hud-card { padding: 8px 6px; }
  .hud-value { font-size: 1rem; }
}
