/* 樂段拼拼樂 — 曲式拼圖 mini-game（風格跟 bridge / merge） */

.form-panel {
  --form-ink: #2e4a62;
  --form-ink-soft: #4a6578;
  --form-a: #fff59d;
  --form-a-border: #f9a825;
  --form-b: #a5d6a7;
  --form-b-border: #43a047;
  --form-slot: #fffde7;
  --form-rail-width: var(--control-rail-width, clamp(160px, 28vw, 220px));
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  padding:
    max(6px, env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
  box-sizing: border-box;
  overflow: hidden;
  background: linear-gradient(180deg, #b3e5fc 0%, #c8e6c9 45%, #fff9c4 100%);
}

.form-panel[hidden] {
  display: none !important;
}

.form-panel__deco {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.form-panel__cloud {
  position: absolute;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 2px 8px rgba(255, 255, 255, 0.5);
}

.form-panel__cloud--1 { width: 5rem; height: 2rem; top: 8%; left: 6%; }
.form-panel__cloud--2 { width: 4rem; height: 1.6rem; top: 12%; right: 8%; }
.form-panel__cloud--3 { width: 6rem; height: 2.2rem; bottom: 18%; left: 10%; }

.form-panel > *:not(.form-panel__deco) {
  position: relative;
  z-index: 1;
}

/* Cover */
.form-cover-screen .cover-title--form {
  font-size: clamp(1rem, 4vw, 1.55rem);
}

.form-cover-chain {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.4rem 0.55rem;
  margin: 1rem auto;
  max-width: 22rem;
}

.form-cover-block {
  min-width: 3rem;
  height: 3rem;
  padding: 0 0.65rem;
  border-radius: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.55rem, 2.8vw, 0.72rem);
  font-weight: 700;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12);
}

.form-cover-block--a {
  background: var(--form-a);
  border: 2px solid var(--form-a-border);
  color: #5d4037;
}

.form-cover-block--b {
  background: var(--form-b);
  border: 2px solid var(--form-b-border);
  color: #1b5e20;
}

.form-cover-chain__arrow {
  color: rgba(255, 255, 255, 0.95);
  font-size: 0.95rem;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.form-cover-learn {
  margin: 0.5rem auto 0;
  max-width: 20rem;
  font-size: clamp(0.78rem, 2.5vw, 0.92rem);
  line-height: 1.55;
  color: #37474f;
  text-align: center;
}

/* Header */
.form-header {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: clamp(4px, 1vmin, 8px);
}

.form-header__title-block { flex: 1; min-width: 0; }

.form-header__title {
  margin: 0;
  font-size: clamp(1rem, 2.8vh, 1.3rem);
  font-weight: 800;
  color: var(--form-ink);
}

.form-header__subtitle {
  margin: 0.25rem 0 0;
  font-size: clamp(0.72rem, 2vh, 0.88rem);
  color: var(--form-ink-soft);
  line-height: 1.45;
}

.form-header__back {
  flex-shrink: 0;
  min-height: 48px;
  padding: 0.4rem 0.65rem;
  border-radius: 0.5rem;
  border: 2px solid #78909c;
  background: rgba(255, 255, 255, 0.75);
  color: var(--form-ink);
  font-weight: 700;
  cursor: pointer;
}

/* Body */
.form-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 2vw, 14px);
}

.form-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: clamp(10px, 2.5vw, 16px);
  padding: clamp(8px, 2vw, 14px);
  background: rgba(255, 255, 255, 0.55);
  border-radius: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.06);
}

.form-form-tag {
  margin: 0;
  text-align: center;
  font-size: clamp(0.8rem, 2.2vw, 0.95rem);
  font-weight: 700;
  color: #455a64;
}

.form-task-hint {
  margin: 0;
  text-align: center;
  font-size: clamp(0.88rem, 2.4vw, 1.05rem);
  color: var(--form-ink);
  line-height: 1.45;
}

/* Playback progress */
.form-playback {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.5rem;
  flex-wrap: wrap;
}

.form-playback__dot {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.55rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.45rem, 2vw, 0.55rem);
  font-weight: 700;
  opacity: 0.45;
  transition: opacity 0.15s, transform 0.15s, box-shadow 0.15s;
}

.form-playback__dot--a {
  background: var(--form-a);
  border: 2px solid var(--form-a-border);
  color: #5d4037;
}

.form-playback__dot--b {
  background: var(--form-b);
  border: 2px solid var(--form-b-border);
  color: #1b5e20;
}

.form-playback__dot.is-active {
  opacity: 1;
  transform: scale(1.08);
  box-shadow: 0 0 0 3px rgba(79, 195, 247, 0.45);
}

/* Slots */
.form-slots {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 0.5rem 0;
}

.form-slot {
  width: 80px;
  height: 80px;
  min-width: 72px;
  min-height: 72px;
  border-radius: 16px;
  border: 3px dashed #90a4ae;
  background: var(--form-slot);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  touch-action: none;
}

.form-slot.is-over {
  border-color: #4fc3f7;
  background: #e1f5fe;
  box-shadow: 0 0 0 3px rgba(79, 195, 247, 0.35);
}

.form-slot.is-filled {
  border-style: solid;
  border-color: #78909c;
}

.form-slot.is-wrong {
  border-color: #ffb74d;
  background: #fff3e0;
  animation: form-slot-wobble 0.35s ease;
}

.form-slot.is-correct {
  border-color: #66bb6a;
  box-shadow: 0 0 0 3px rgba(102, 187, 106, 0.35);
}

@keyframes form-slot-wobble {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* Pieces */
.form-tray {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  min-height: 88px;
  padding: 0.35rem;
}

.form-piece {
  width: 80px;
  height: 80px;
  min-width: 72px;
  min-height: 72px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.65rem, 3vw, 0.8rem);
  font-weight: 700;
  cursor: grab;
  touch-action: none;
  user-select: none;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12);
  transition: transform 0.12s, box-shadow 0.12s;
}

.form-piece:active,
.form-piece.is-dragging {
  cursor: grabbing;
  transform: scale(1.08);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.18);
  z-index: 50;
}

.form-piece.is-selected {
  outline: 3px solid #4fc3f7;
  outline-offset: 2px;
}

.form-piece--a {
  background: var(--form-a);
  border: 3px solid var(--form-a-border);
  color: #5d4037;
}

.form-piece--b {
  background: var(--form-b);
  border: 3px solid var(--form-b-border);
  color: #1b5e20;
}

.form-piece__icon {
  font-size: 1.25rem;
  line-height: 1;
}

.form-piece--in-slot {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border-radius: 12px;
  box-shadow: none;
  cursor: grab;
}

/* Identify choices */
.form-choices {
  display: flex;
  align-items: stretch;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
}

.form-choice-btn {
  min-width: 8.5rem;
  min-height: 56px;
  padding: 0.65rem 1rem;
  border-radius: 14px;
  border: 3px solid #78909c;
  background: rgba(255, 255, 255, 0.9);
  font-size: clamp(0.85rem, 2.5vw, 1rem);
  font-weight: 800;
  color: var(--form-ink);
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.1);
}

.form-choice-btn:active {
  transform: translateY(2px);
  box-shadow: none;
}

.form-choice-btn.is-wrong {
  border-color: #ffb74d;
  background: #fff3e0;
}

.form-choice-btn.is-correct {
  border-color: #66bb6a;
  background: #e8f5e9;
}

/* Controls footer */
.form-controls {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0.35rem 0;
}

.form-btn {
  min-height: 56px;
  padding: 0.55rem 1.15rem;
  border-radius: 14px;
  border: 2px solid transparent;
  font-size: clamp(0.9rem, 2.5vw, 1.05rem);
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12);
}

.form-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: none;
}

.form-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.form-btn--primary {
  background: #42a5f5;
  border-color: #1565c0;
  color: #fff;
  min-width: 7.5rem;
}

.form-btn--secondary {
  min-height: 48px;
  background: rgba(255, 255, 255, 0.85);
  border-color: #78909c;
  color: var(--form-ink);
}

.form-btn--submit {
  background: #66bb6a;
  border-color: #2e7d32;
  color: #fff;
}

.form-progress-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: clamp(0.75rem, 2vh, 0.88rem);
  color: var(--form-ink-soft);
  font-weight: 700;
}

.form-stars {
  letter-spacing: 0.15em;
  color: #f9a825;
  font-size: 1.1rem;
}

.form-feedback {
  margin: 0;
  text-align: center;
  min-height: 1.4em;
  font-size: clamp(0.88rem, 2.4vw, 1rem);
  font-weight: 700;
  color: var(--form-ink);
}

.form-feedback--success { color: #2e7d32; }
.form-feedback--soft { color: #e65100; }

/* Intro modal */
.form-intro {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(26, 42, 58, 0.55);
}

.form-intro[hidden] {
  display: none !important;
}

.form-intro__card {
  width: min(22rem, 100%);
  padding: 1.25rem 1.15rem;
  border-radius: 1rem;
  background: #fffde7;
  border: 3px solid #4fc3f7;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.12);
}

.form-intro__title {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--form-ink);
  text-align: center;
}

.form-intro__steps {
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.form-intro__steps li {
  font-size: 0.92rem;
  line-height: 1.45;
  color: #37474f;
  padding-left: 1.6rem;
  position: relative;
}

.form-intro__steps li::before {
  content: attr(data-step);
  position: absolute;
  left: 0;
  font-weight: 800;
  color: #1565c0;
}

.form-intro__form-note {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  line-height: 1.5;
  color: #546e7a;
  text-align: center;
}

.form-intro__btn {
  width: 100%;
  min-height: 56px;
  border-radius: 14px;
  border: 2px solid #2e7d32;
  background: #66bb6a;
  color: #fff;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
}

/* Result overlay */
.form-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(38, 59, 85, 0.45);
  border-radius: 1rem;
}

.form-overlay[hidden] {
  display: none !important;
}

.form-overlay__card {
  width: min(18rem, 100%);
  padding: 1.25rem;
  border-radius: 1rem;
  background: #fff;
  border: 3px solid #4fc3f7;
  text-align: center;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.1);
}

.form-overlay__stars {
  font-size: 1.75rem;
  color: #f9a825;
  letter-spacing: 0.2em;
  margin-bottom: 0.5rem;
}

.form-overlay__title {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--form-ink);
}

.form-overlay__text {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--form-ink-soft);
}

.form-overlay__actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

@media (max-width: 720px), (orientation: portrait) {
  .form-stage {
    min-height: 12rem;
  }

  .form-slot,
  .form-piece {
    width: 76px;
    height: 76px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .form-header__title { font-size: 1rem; }
  .form-slot,
  .form-piece {
    width: 68px;
    height: 68px;
  }
  .form-btn { min-height: 48px; }
  .form-btn--primary { min-height: 52px; }
}
