/* ═══════════════════════════════════════════════
   AVALYNIA — A Forest Melody — Styles
   ═══════════════════════════════════════════════ */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
body {
  overflow: hidden;
  background: #0a0612;
  font-family: 'Nunito', sans-serif;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
}
canvas#game { display: block; width: 100vw; height: 100vh; }

/* ── Title Screen ── */
#title-screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 100;
  background: radial-gradient(ellipse at 50% 80%, #1a1040 0%, #0a0612 70%);
  transition: opacity 1.2s ease;
}
#title-screen.hidden { opacity: 0; pointer-events: none; }
#title-screen h1 {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(3rem, 8vw, 6rem);
  font-weight: 600; color: #e8d5b7;
  letter-spacing: 0.15em;
  text-shadow: 0 0 40px rgba(232,213,183,0.3), 0 0 80px rgba(180,140,255,0.15);
  margin-bottom: 0.5rem;
  animation: titleFloat 4s ease-in-out infinite;
}
#title-screen .subtitle {
  font-family: 'Cormorant Garamond', serif; font-style: italic;
  font-size: clamp(1rem, 2.5vw, 1.4rem); color: #a08bc0;
  letter-spacing: 0.3em; margin-bottom: 3rem;
}
#title-screen .prompt {
  font-size: 0.95rem; color: #7a6a90;
  letter-spacing: 0.2em; animation: promptPulse 2.5s ease-in-out infinite;
}
#title-screen .title-buttons {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  margin-bottom: 1.5rem;
}
#title-screen .title-btn {
  background: rgba(232,213,183,0.08); border: 1px solid rgba(232,213,183,0.2);
  color: #e8d5b7; padding: 10px 40px; border-radius: 24px;
  font-family: 'Nunito', sans-serif; font-size: 0.95rem;
  letter-spacing: 0.15em; cursor: pointer; transition: all 0.3s ease;
  min-width: 200px;
}
#title-screen .title-btn:hover {
  background: rgba(232,213,183,0.18); border-color: rgba(232,213,183,0.4);
  transform: scale(1.03);
}
#title-screen .title-btn.continue-btn {
  border-color: rgba(244,208,63,0.3); color: #f4d03f;
}
#title-screen .title-btn.continue-btn:hover {
  background: rgba(244,208,63,0.12); border-color: rgba(244,208,63,0.5);
}
#title-screen .continue-info {
  font-size: 0.7rem; color: rgba(244,208,63,0.4);
  letter-spacing: 0.1em; margin-top: -6px;
}
@keyframes titleFloat { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-8px)} }
@keyframes promptPulse { 0%,100%{opacity:0.4} 50%{opacity:1} }

.title-firefly {
  position: absolute; width: 4px; height: 4px;
  background: radial-gradient(circle, #f4d03f, transparent);
  border-radius: 50%; animation: fireflyDrift 6s ease-in-out infinite;
}
@keyframes fireflyDrift {
  0%,100%{transform:translate(0,0);opacity:0.2} 25%{transform:translate(20px,-30px);opacity:0.8}
  50%{transform:translate(-10px,-50px);opacity:0.3} 75%{transform:translate(30px,-20px);opacity:0.9}
}

/* ── HUD ── */
#hud {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 20px 28px; z-index: 50; pointer-events: none;
  opacity: 0; transition: opacity 0.6s ease;
}
#hud.visible { opacity: 1; }
#hud .area-name {
  font-family: 'Cormorant Garamond', serif; font-style: italic;
  font-size: 1.1rem; color: rgba(232,213,183,0.6); letter-spacing: 0.15em;
}
#hud .level-badge {
  font-size: 0.7rem; color: rgba(244,208,63,0.6); letter-spacing: 0.15em;
  margin-bottom: 4px;
}
#hud .stats { display: flex; gap: 16px; align-items: center; }
#hud .animal-count { font-size: 0.85rem; color: rgba(232,213,183,0.7); letter-spacing: 0.1em; }
#hud .journal-btn {
  pointer-events: all;
  background: rgba(232,213,183,0.1); border: 1px solid rgba(232,213,183,0.2);
  color: #e8d5b7; padding: 6px 16px; border-radius: 20px;
  font-family: 'Nunito', sans-serif; font-size: 0.8rem;
  letter-spacing: 0.1em; cursor: pointer; transition: all 0.3s ease;
}
#hud .journal-btn:hover { background: rgba(232,213,183,0.2); border-color: rgba(232,213,183,0.4); }
#companion-btn { margin-right: 0; }

/* ── Dialogue Box ── */
#dialogue {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  width: min(600px, 85vw);
  background: linear-gradient(135deg, rgba(42,30,55,0.95), rgba(30,22,42,0.95));
  border: 1px solid rgba(180,140,255,0.2); border-radius: 16px;
  padding: 24px 28px; z-index: 60;
  opacity: 0; pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
  backdrop-filter: blur(10px);
}
#dialogue.visible { opacity: 1; pointer-events: all; transform: translateX(-50%) translateY(0); }
#dialogue.hidden-shift { transform: translateX(-50%) translateY(20px); }
#dialogue .speaker {
  font-family: 'Cormorant Garamond', serif; font-size: 1.1rem;
  font-weight: 600; color: #c4a0e8; margin-bottom: 8px; letter-spacing: 0.08em;
}
#dialogue .text { font-size: 0.95rem; color: #d4c8e0; line-height: 1.6; }
#dialogue .continue {
  text-align: right; margin-top: 12px; font-size: 0.75rem;
  color: rgba(180,140,255,0.5); letter-spacing: 0.15em;
  animation: promptPulse 2s ease-in-out infinite;
}

/* ── Piano Container (BIGGER) ── */
#piano-container {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 70;
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 20px 24px;
  background: linear-gradient(to top, rgba(20,14,30,0.97), rgba(20,14,30,0.85), transparent);
  opacity: 0; pointer-events: none; transform: translateY(30px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}
#piano-container.visible { opacity: 1; pointer-events: all; transform: translateY(0); }

#piano-status {
  font-family: 'Cormorant Garamond', serif; font-style: italic;
  font-size: 1.2rem; color: #c4a0e8; margin-bottom: 10px;
  letter-spacing: 0.1em; min-height: 1.4em;
}

/* Dragon battle round indicator */
#battle-rounds {
  display: flex; gap: 12px; margin-bottom: 10px; min-height: 20px;
}
#battle-rounds .round-pip {
  width: 32px; height: 6px; border-radius: 3px;
  background: rgba(180,140,255,0.15); border: 1px solid rgba(180,140,255,0.2);
  transition: all 0.4s ease;
}
#battle-rounds .round-pip.won {
  background: #6ec87a; border-color: #6ec87a;
  box-shadow: 0 0 10px rgba(110,200,122,0.4);
}
#battle-rounds .round-pip.current {
  background: rgba(244,208,63,0.3); border-color: #f4d03f;
  box-shadow: 0 0 10px rgba(244,208,63,0.3);
  animation: promptPulse 1.5s ease-in-out infinite;
}
#battle-rounds .round-pip.lost {
  background: #d44; border-color: #d44;
}

#melody-progress { display: flex; gap: 8px; margin-bottom: 12px; }
#melody-progress .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: rgba(180,140,255,0.15); border: 1px solid rgba(180,140,255,0.3);
  transition: all 0.3s ease;
}
#melody-progress .dot.completed {
  background: #a78bfa; border-color: #a78bfa;
  box-shadow: 0 0 8px rgba(167,139,250,0.5);
}
#melody-progress .dot.current {
  background: rgba(244,208,63,0.3); border-color: #f4d03f;
  box-shadow: 0 0 12px rgba(244,208,63,0.4);
  animation: promptPulse 1.5s ease-in-out infinite;
}

#piano { position: relative; display: flex; height: 170px; }

.piano-key {
  position: relative; width: 60px; height: 170px;
  background: linear-gradient(to bottom, #f5f0e8, #e8e0d4);
  border: 1px solid rgba(60,40,30,0.25); border-radius: 0 0 7px 7px;
  cursor: pointer; display: flex; flex-direction: column;
  align-items: center; justify-content: flex-end; padding-bottom: 14px;
  transition: background 0.1s ease; z-index: 1;
}
.piano-key .key-label { font-size: 0.8rem; font-weight: 700; color: rgba(60,40,30,0.4); }
.piano-key .note-name { font-size: 0.65rem; color: rgba(60,40,30,0.25); margin-bottom: 3px; }
.piano-key.active {
  background: linear-gradient(to bottom, #d4c8ff, #b8a8e8);
  box-shadow: 0 0 24px rgba(180, 140, 255, 0.5);
}
.piano-key.correct { background: linear-gradient(to bottom, #b8e8c8, #90d8a8) !important; box-shadow: 0 0 24px rgba(100,220,140,0.5); }
.piano-key.wrong { background: linear-gradient(to bottom, #e8b8b8, #d89090) !important; box-shadow: 0 0 24px rgba(220,100,100,0.5); }
.piano-key.hint { box-shadow: inset 0 -5px 0 rgba(244,208,63,0.5), 0 0 18px rgba(244,208,63,0.25); }

.piano-key-black {
  position: absolute; width: 38px; height: 105px;
  background: linear-gradient(to bottom, #2c1f18, #1a1210);
  border-radius: 0 0 5px 5px; cursor: pointer;
  display: flex; flex-direction: column;
  align-items: center; justify-content: flex-end; padding-bottom: 10px;
  z-index: 2; top: 0; transition: background 0.1s ease;
}
.piano-key-black .key-label { font-size: 0.65rem; font-weight: 700; color: rgba(200,180,160,0.4); }
.piano-key-black.active {
  background: linear-gradient(to bottom, #5a3d8a, #3d2860);
  box-shadow: 0 0 18px rgba(180, 140, 255, 0.5);
}
.piano-key-black.correct { background: linear-gradient(to bottom, #2a6838, #1a4828) !important; box-shadow: 0 0 18px rgba(100,220,140,0.4); }
.piano-key-black.wrong { background: linear-gradient(to bottom, #6a2828, #4a1818) !important; box-shadow: 0 0 18px rgba(220,100,100,0.4); }
.piano-key-black.hint { box-shadow: inset 0 -4px 0 rgba(244,208,63,0.5), 0 0 14px rgba(244,208,63,0.25); }

/* ── Journal ── */
#journal {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10,6,18,0.85); backdrop-filter: blur(8px);
  opacity: 0; pointer-events: none; transition: opacity 0.4s ease;
}
#journal.visible { opacity: 1; pointer-events: all; }
#journal-book {
  width: min(700px, 90vw); max-height: 80vh;
  background: linear-gradient(135deg, #2a1e37, #1e1628);
  border: 1px solid rgba(180,140,255,0.15); border-radius: 16px;
  padding: 36px 32px; overflow-y: auto;
}
#journal-book::-webkit-scrollbar { width: 6px; }
#journal-book::-webkit-scrollbar-track { background: transparent; }
#journal-book::-webkit-scrollbar-thumb { background: rgba(180,140,255,0.2); border-radius: 3px; }
#journal-book h2 {
  font-family: 'Cormorant Garamond', serif; font-size: 1.8rem;
  color: #e8d5b7; text-align: center; margin-bottom: 8px; letter-spacing: 0.15em;
}
.journal-subtitle {
  text-align: center; font-size: 0.8rem; color: rgba(180,140,255,0.5);
  letter-spacing: 0.2em; margin-bottom: 28px;
}
.journal-section-title {
  font-family: 'Cormorant Garamond', serif; font-size: 1rem;
  color: rgba(244,208,63,0.5); letter-spacing: 0.2em; text-align: center;
  margin: 20px 0 12px; border-top: 1px solid rgba(180,140,255,0.08); padding-top: 16px;
}
.journal-entry {
  display: flex; gap: 18px; align-items: flex-start;
  padding: 14px 0; border-bottom: 1px solid rgba(180,140,255,0.08);
}
.journal-entry:last-child { border-bottom: none; }
.journal-entry .animal-icon {
  width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 1.6rem;
}
.journal-entry .animal-info h3 {
  font-family: 'Cormorant Garamond', serif; font-size: 1.15rem;
  color: #d4c0e8; margin-bottom: 4px;
}
.journal-entry .animal-info p { font-size: 0.85rem; color: rgba(200,185,215,0.7); line-height: 1.5; }
.journal-entry.locked .animal-icon { background: rgba(180,140,255,0.08); color: rgba(180,140,255,0.2); }
.journal-entry.locked .animal-info h3 { color: rgba(180,140,255,0.3); }
.journal-entry.locked .animal-info p { color: rgba(180,140,255,0.15); }
#journal-close {
  display: block; margin: 24px auto 0;
  background: rgba(180,140,255,0.1); border: 1px solid rgba(180,140,255,0.2);
  color: #c4a0e8; padding: 8px 28px; border-radius: 20px;
  font-family: 'Nunito', sans-serif; font-size: 0.85rem;
  cursor: pointer; letter-spacing: 0.1em; transition: all 0.3s ease;
}
#journal-close:hover { background: rgba(180,140,255,0.2); }

/* ── Level Transition ── */
#level-transition {
  position: fixed; inset: 0; z-index: 95;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: #0a0612;
  opacity: 0; pointer-events: none; transition: opacity 1.2s ease;
}
#level-transition.visible { opacity: 1; pointer-events: all; }
#level-transition h1 {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(2rem, 5vw, 3.5rem); color: #e8d5b7;
  letter-spacing: 0.2em;
  text-shadow: 0 0 40px rgba(232,213,183,0.3);
}
#level-transition p {
  font-family: 'Cormorant Garamond', serif; font-style: italic;
  font-size: 1.2rem; color: #a08bc0; margin-top: 1rem;
  letter-spacing: 0.15em; text-align: center; max-width: 500px; line-height: 1.8;
}

/* ── Concert / Ending ── */
#concert {
  position: fixed; inset: 0; z-index: 90;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 60%, #1a1040, #0a0612);
  opacity: 0; pointer-events: none; transition: opacity 1.5s ease;
}
#concert.visible { opacity: 1; pointer-events: all; }
#concert h1 {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(2rem, 5vw, 3.5rem); color: #e8d5b7;
  letter-spacing: 0.15em; text-shadow: 0 0 40px rgba(232,213,183,0.3);
  margin-bottom: 1rem;
}
#concert p {
  font-family: 'Cormorant Garamond', serif; font-style: italic;
  font-size: 1.2rem; color: #a08bc0; text-align: center;
  max-width: 550px; line-height: 1.8;
}

/* ── Scene Continue Hint (double-tap) ── */
.scene-continue-hint {
  position: absolute; bottom: 8%;
  font-size: 0.85rem; color: rgba(180,140,255,0.4);
  letter-spacing: 0.18em;
  opacity: 0; transition: opacity 1.2s ease;
  pointer-events: none;
}
.scene-continue-hint.show {
  opacity: 1;
  animation: promptPulse 2.5s ease-in-out infinite;
}

/* ── Interaction Prompt ── */
#interact-prompt {
  position: fixed; z-index: 55; font-size: 0.8rem; color: #f4d03f;
  letter-spacing: 0.15em; background: rgba(20,14,30,0.8);
  padding: 5px 14px; border-radius: 12px;
  border: 1px solid rgba(244,208,63,0.2);
  opacity: 0; pointer-events: none; transition: opacity 0.3s ease; white-space: nowrap;
}
#interact-prompt.visible { opacity: 1; }

/* ── Companion Selector ── */
#companion-selector {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10,6,18,0.88); backdrop-filter: blur(8px);
  opacity: 0; pointer-events: none; transition: opacity 0.35s ease;
}
#companion-selector.visible { opacity: 1; pointer-events: all; }
#companion-panel {
  width: min(650px, 92vw); max-height: 82vh;
  background: linear-gradient(135deg, #1e1830, #161022);
  border: 1px solid rgba(244,208,63,0.12); border-radius: 18px;
  padding: 28px 26px; overflow-y: auto;
}
#companion-panel::-webkit-scrollbar { width: 5px; }
#companion-panel::-webkit-scrollbar-track { background: transparent; }
#companion-panel::-webkit-scrollbar-thumb { background: rgba(244,208,63,0.15); border-radius: 3px; }
.comp-header {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 16px;
}
.comp-header h2 {
  font-family: 'Cormorant Garamond', serif; font-size: 1.6rem;
  color: #e8d5b7; letter-spacing: 0.12em;
}
#companion-slot-info {
  font-size: 0.8rem; color: rgba(244,208,63,0.5); letter-spacing: 0.1em;
}
#companion-slots {
  display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap;
}
.companion-slot {
  flex: 1; min-width: 80px; padding: 10px 8px; text-align: center;
  border: 1px dashed rgba(244,208,63,0.15); border-radius: 10px;
  background: rgba(244,208,63,0.03); cursor: default;
  transition: all 0.25s ease;
}
.companion-slot.filled {
  border-style: solid; border-color: rgba(244,208,63,0.3);
  background: rgba(244,208,63,0.06); cursor: pointer;
}
.companion-slot.filled:hover {
  background: rgba(220,80,80,0.1); border-color: rgba(220,80,80,0.4);
}
.slot-name {
  font-size: 0.75rem; color: #e8d5b7; letter-spacing: 0.05em;
}
.slot-empty {
  font-size: 0.7rem; color: rgba(180,140,255,0.25); letter-spacing: 0.08em;
}
.comp-section { margin-bottom: 18px; }
.comp-section-title {
  font-family: 'Cormorant Garamond', serif; font-size: 0.85rem;
  color: rgba(244,208,63,0.4); letter-spacing: 0.18em;
  margin-bottom: 10px; padding-bottom: 6px;
  border-bottom: 1px solid rgba(244,208,63,0.08);
}
.comp-animal-grid {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.comp-animal-card {
  padding: 8px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid rgba(180,140,255,0.12);
  background: rgba(180,140,255,0.04);
  transition: all 0.25s ease; position: relative;
}
.comp-animal-card:hover {
  background: rgba(180,140,255,0.12); border-color: rgba(180,140,255,0.3);
  transform: translateY(-1px);
}
.comp-animal-card.active {
  border-color: rgba(244,208,63,0.4); background: rgba(244,208,63,0.08);
  box-shadow: 0 0 12px rgba(244,208,63,0.1);
}
.comp-animal-card.boss { border-color: rgba(220,100,120,0.2); }
.comp-animal-card.boss.active { border-color: rgba(220,100,120,0.5); background: rgba(220,100,120,0.08); }
.comp-animal-name {
  font-size: 0.85rem; color: #d4c0e8; font-weight: 600;
}
.comp-animal-full {
  font-size: 0.65rem; color: rgba(200,185,215,0.5); margin-top: 2px;
}
.comp-boss-badge {
  position: absolute; top: 4px; right: 6px;
  font-size: 0.5rem; color: rgba(220,100,120,0.6);
  letter-spacing: 0.1em; font-weight: 700;
}
.comp-hint {
  text-align: center; margin-top: 16px;
  font-size: 0.72rem; color: rgba(180,140,255,0.25);
  letter-spacing: 0.12em;
}

#controls-help {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  font-size: 0.75rem; color: rgba(180,140,255,0.3); letter-spacing: 0.15em;
  z-index: 55; pointer-events: none; opacity: 0; transition: opacity 0.6s ease 1s;
}
#controls-help.visible { opacity: 1; }

/* ── Level Select (in journal) ── */
.level-select {
  margin-top: 24px; padding-top: 20px;
  border-top: 1px solid rgba(244,208,63,0.15);
}
.level-select-title {
  font-family: 'Cormorant Garamond', serif; font-size: 0.85rem;
  color: rgba(244,208,63,0.4); letter-spacing: 0.2em; text-align: center;
  margin-bottom: 14px;
}
.level-select-btns {
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
}
.level-select-btns button {
  background: rgba(244,208,63,0.06); border: 1px solid rgba(244,208,63,0.15);
  color: rgba(244,208,63,0.6); padding: 8px 20px; border-radius: 16px;
  font-family: 'Nunito', sans-serif; font-size: 0.8rem;
  letter-spacing: 0.1em; cursor: pointer; transition: all 0.3s ease;
}
.level-select-btns button:hover {
  background: rgba(244,208,63,0.15); border-color: rgba(244,208,63,0.4);
  color: #f4d03f;
}

/* Voice test (diagnostics) */
.voice-test-btn {
  margin-top: 24px !important;
  background: rgba(232, 213, 183, 0.08) !important;
  border: 1px solid rgba(232, 213, 183, 0.35) !important;
  color: rgba(232, 213, 183, 0.85) !important;
  padding: 10px 22px !important;
  font-size: 0.85rem !important;
  letter-spacing: 0.1em !important;
  cursor: pointer;
  min-height: 44px;
}
.voice-test-btn:active { transform: scale(0.96); }
.voice-test-status {
  font-family: monospace;
  font-size: 0.75rem;
  color: rgba(244, 208, 63, 0.85);
  margin-top: 10px;
  min-height: 1em;
  text-align: center;
}

/* ═══════════════════════════════════════════════
   TOUCH CONTROLS — on-screen D-pad + action buttons
   ═══════════════════════════════════════════════ */

.touch-device #piano-container,
.touch-device #journal,
.touch-device #companion-selector,
.touch-device #dialogue,
.touch-device #concert,
.touch-device #level-transition,
.touch-device #title-screen {
  touch-action: manipulation;
}
.touch-device canvas#game { touch-action: none; }
.touch-device .piano-key,
.touch-device .piano-key-black {
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.15s ease;
}
/* Tactile press feedback on touch */
.touch-device .piano-key:active {
  transform: scale(0.96) translateY(2px);
  background: linear-gradient(to bottom, #e8dcff, #c8b8e8) !important;
  box-shadow: 0 0 20px rgba(180, 140, 255, 0.5), inset 0 2px 6px rgba(60, 40, 100, 0.25);
}
.touch-device .piano-key-black:active {
  transform: scale(0.95) translateY(2px);
  background: linear-gradient(to bottom, #5a3d8a, #2d1d4a) !important;
  box-shadow: 0 0 18px rgba(244, 208, 63, 0.4), inset 0 2px 6px rgba(0, 0, 0, 0.45);
}

/* Piano scrolls horizontally if it overflows on narrow screens */
.touch-device #piano {
  overflow-x: auto;
  overflow-y: visible;
  max-width: 100vw;
  padding: 0 6px;
  scrollbar-width: thin;
}
.touch-device #piano::-webkit-scrollbar { height: 4px; }
.touch-device #piano::-webkit-scrollbar-thumb { background: rgba(180, 140, 255, 0.35); border-radius: 2px; }

/* Brighter, more obvious key labels on touch */
.touch-device .piano-key .note-name {
  color: rgba(60, 40, 30, 0.75);
  font-weight: 800;
  font-size: 0.85rem;
}
.touch-device .piano-key .key-label { display: none; } /* hide QWERTY label — irrelevant on touch */
.touch-device .piano-key-black .key-label { display: none; }

#touch-controls {
  position: fixed;
  inset: 0;
  z-index: 150;
  pointer-events: none;
}

/* ── Screen-edge touch zones — invisible walking areas ────────── */
.tc-zone {
  position: absolute;
  top: 80px;         /* clear of the HUD at the top */
  bottom: 0;
  width: 45vw;
  max-width: 380px;  /* on iPad, don't overreach into middle */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
}
.tc-zone-left  { left: 0;  justify-content: flex-start; padding-left: 18px; }
.tc-zone-right { right: 0; justify-content: flex-end;   padding-right: 18px; }

#touch-controls.show-zones .tc-zone {
  opacity: 1;
  pointer-events: auto;
}

/* Themed gradient so the zones feel like part of the forest,
   not a grey overlay. Soft purple→gold edge glow pulses gently
   when idle and brightens to firefly-gold on touch. */
.tc-zone::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: background 0.3s ease;
  background: transparent;
}
/* Zones stay invisible. Only the arrow hint shows — small, themed,
   and just subtly brightens on press. No gradient wash. */
.tc-zone::before { display: none; }

.tc-zone-hint {
  position: relative;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 1.6rem;
  color: rgba(200, 165, 230, 0.85);
  background: radial-gradient(circle at 35% 28%,
    rgba(180, 140, 255, 0.35) 0%,
    rgba(90, 60, 150, 0.55) 60%,
    rgba(40, 20, 70, 0.7) 100%);
  border: 1px solid rgba(180, 140, 255, 0.45);
  box-shadow:
    0 4px 14px rgba(10, 6, 18, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  font-family: 'Cormorant Garamond', serif;
  transition: transform 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  user-select: none;
  pointer-events: none;
}
.tc-zone.pressed .tc-zone-hint {
  color: #e8d5b7;
  transform: scale(1.1);
  border-color: rgba(220, 190, 255, 0.85);
  box-shadow:
    0 4px 14px rgba(10, 6, 18, 0.5),
    0 0 16px rgba(180, 140, 255, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

/* Action button container */
.tc-actions {
  position: absolute;
  bottom: calc(30px + env(safe-area-inset-bottom));
  right: calc(22px + env(safe-area-inset-right));
  opacity: 0;
  transform: scale(0.7);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.4s cubic-bezier(.34,1.56,.64,1);
  z-index: 2;
}
#touch-controls.show-action .tc-actions {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.tc-btn {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid rgba(232, 213, 183, 0.35);
  background: radial-gradient(circle at 35% 30%, rgba(160, 139, 192, 0.42), rgba(26, 16, 64, 0.55));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: rgba(232, 213, 183, 0.9);
  font-family: 'Cormorant Garamond', serif;
  font-size: 20px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 14px rgba(10, 6, 18, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  touch-action: none;
}
.tc-btn.pressed {
  transform: scale(0.88);
  background: radial-gradient(circle at 35% 30%, rgba(244, 208, 63, 0.5), rgba(110, 70, 170, 0.6));
  border-color: rgba(244, 208, 63, 0.75);
  box-shadow: 0 2px 8px rgba(10, 6, 18, 0.35), inset 0 2px 6px rgba(244, 208, 63, 0.25);
}

/* D-pad cross layout */
.tc-dpad .tc-btn {
  width: 60px;
  height: 60px;
  border-radius: 16px;
  font-size: 22px;
}
.tc-up    { top: 0;    left: 60px; }
.tc-left  { top: 60px; left: 0; }
.tc-right { top: 60px; right: 0; }
.tc-down  { bottom: 0; left: 60px; }

/* D-pad center ornament (just visual filler) */
.tc-dpad::after {
  content: '';
  position: absolute;
  top: 66px; left: 66px;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(244, 208, 63, 0.12), transparent 70%);
  pointer-events: none;
}

/* Action button — purple forest orb. Brightens to pink when ready,
   pops pink on press. No more grey/gold/orange. */
.tc-action {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  font-size: 30px;
  color: #e8d5b7;
  border-color: rgba(180, 140, 255, 0.55);
  background: radial-gradient(circle at 35% 28%,
    rgba(200, 160, 232, 0.65) 0%,
    rgba(140, 100, 200, 0.7) 40%,
    rgba(58, 30, 110, 0.9) 100%);
  transition: transform 0.2s ease, background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease, color 0.25s ease;
  box-shadow:
    0 4px 16px rgba(10, 6, 18, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
/* Ready breath — soft pink glow pulses when there's an action nearby */
#touch-controls.action-ready .tc-action {
  color: #ffe0ec;
  border-color: rgba(236, 106, 155, 0.75);
  background: radial-gradient(circle at 35% 28%,
    rgba(248, 180, 210, 0.6) 0%,
    rgba(200, 120, 180, 0.75) 45%,
    rgba(100, 50, 110, 0.9) 100%);
  animation: tcReadyPulse 2.8s ease-in-out infinite;
}
.tc-action.pressed {
  animation: none;
  transform: scale(0.9);
  background: radial-gradient(circle at 35% 28%,
    rgba(255, 200, 220, 0.75) 0%,
    rgba(236, 106, 155, 0.85) 45%,
    rgba(130, 60, 140, 0.95) 100%);
  border-color: rgba(255, 180, 210, 0.95);
  color: #fff;
}
@keyframes tcReadyPulse {
  0%, 100% {
    box-shadow:
      0 4px 16px rgba(10, 6, 18, 0.5),
      0 0 0 0 rgba(236, 106, 155, 0),
      inset 0 1px 0 rgba(255, 255, 255, 0.15);
    transform: scale(1);
  }
  50% {
    box-shadow:
      0 4px 18px rgba(10, 6, 18, 0.5),
      0 0 26px rgba(236, 106, 155, 0.55),
      0 0 0 8px rgba(236, 106, 155, 0.12),
      inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
  }
}

/* When piano is showing, the piano keys ARE the interaction surface —
   hide zones + action button so they don't float over the keyboard. */
#piano-container.visible ~ #touch-controls .tc-zone,
#piano-container.visible ~ #touch-controls .tc-actions {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* When journal or companion selector is open, hide touch controls too */
#journal.visible ~ #touch-controls,
#companion-selector.visible ~ #touch-controls {
  opacity: 0;
  pointer-events: none;
}

/* ── Companion selector close button ──────────────────────────── */
#companion-panel { position: relative; }
#companion-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(244, 208, 63, 0.1);
  border: 1px solid rgba(244, 208, 63, 0.35);
  color: rgba(244, 208, 63, 0.9);
  font-size: 1.8rem; line-height: 1; font-weight: 400;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0 0 2px;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  z-index: 2;
}
#companion-close:hover, #companion-close:active {
  background: rgba(244, 208, 63, 0.25);
  border-color: rgba(244, 208, 63, 0.6);
  transform: scale(1.08);
}

/* ── Contrast boost — journal + party always more readable ────── */
/* (applies on desktop too since Tim reported low contrast generally) */
#journal-book h2 { color: #f4e8cc; }
.journal-subtitle { color: rgba(220, 200, 245, 0.75); }
.journal-section-title { color: rgba(244, 208, 63, 0.75); }
.journal-entry .animal-info h3 { color: #f0deb8; }
.journal-entry .animal-info p { color: rgba(220, 205, 235, 0.9); }
.journal-entry.locked .animal-info h3 { color: rgba(200, 175, 235, 0.5); }
.journal-entry.locked .animal-info p { color: rgba(200, 175, 235, 0.4); }
#journal-close { color: #f0deb8; background: rgba(244, 208, 63, 0.12); border-color: rgba(244, 208, 63, 0.35); }
#journal-close:hover { background: rgba(244, 208, 63, 0.22); border-color: rgba(244, 208, 63, 0.55); }

#companion-panel h2 { color: #f4e8cc; }
#companion-slot-info { color: rgba(220, 200, 245, 0.85); }
.slot-name { color: #f0deb8; }
.slot-empty { color: rgba(200, 175, 235, 0.55); }
.companion-card-name,
.comp-card-name { color: #f0deb8; }
.comp-hint { color: rgba(220, 200, 245, 0.7); }

/* ── Mobile readability — journal, dialogue, scene text ─────────── */
@media (max-width: 760px), (pointer: coarse) {
  /* Journal — full-screen modal, bigger fonts */
  #journal-book {
    width: 96vw;
    max-height: 94vh;
    padding: 24px 22px 30px;
    border-radius: 18px;
  }
  #journal-book h2 { font-size: 2.1rem; margin-bottom: 6px; }
  .journal-subtitle { font-size: 0.98rem; margin-bottom: 22px; letter-spacing: 0.15em; }
  .journal-section-title { font-size: 1.2rem; margin: 22px 0 14px; padding-top: 18px; }
  .journal-entry { gap: 14px; padding: 16px 0; }
  .journal-entry .animal-icon { width: 54px; height: 54px; font-size: 1.9rem; }
  .journal-entry .animal-info h3 { font-size: 1.35rem; margin-bottom: 6px; }
  .journal-entry .animal-info p { font-size: 1.02rem; line-height: 1.55; }
  #journal-close {
    font-size: 1rem;
    padding: 14px 40px;
    margin-top: 28px;
    border-radius: 24px;
    min-height: 48px;
  }

  /* Companion panel — finger-friendly */
  #companion-panel {
    width: 96vw !important;
    max-height: 90vh !important;
    padding: 24px 20px !important;
  }
  #companion-panel h2 { font-size: 1.8rem; }
  #companion-close { width: 44px; height: 44px; font-size: 2rem; top: 10px; right: 10px; }

  /* Dialogue — more legible */
  #dialogue { padding: 18px 22px; max-width: 92vw; }
  #dialogue .speaker { font-size: 1.05rem; }
  #dialogue .text { font-size: 1.05rem; line-height: 1.55; }
  #dialogue .continue { font-size: 0.85rem; opacity: 0.75; }

  /* Scene text */
  #level-transition h1 { font-size: 2.2rem; letter-spacing: 0.15em; }
  #level-transition p { font-size: 1.05rem; max-width: 92vw; padding: 0 16px; }
  #concert h1 { font-size: 2.2rem; }
  #concert p { font-size: 1.05rem; max-width: 92vw; padding: 0 16px; }
  .scene-continue-hint { font-size: 0.9rem; }

  /* Interact prompt */
  #interact-prompt { font-size: 1rem; padding: 10px 20px; }

  /* HUD buttons — finger-friendly */
  .journal-btn { font-size: 0.95rem; padding: 10px 18px; min-height: 44px; }
}

/* Controls-help line — hide on touch (the on-screen buttons replace it) */
.touch-device #controls-help { display: none; }

/* Slightly bigger piano keys on touch for fat fingers */
.touch-device .piano-key { min-width: 48px; }

@media (max-width: 520px) {
  .tc-dpad { width: 156px; height: 156px; bottom: 18px; left: 16px; }
  .tc-dpad .tc-btn { width: 52px; height: 52px; border-radius: 14px; }
  .tc-up    { top: 0;    left: 52px; }
  .tc-left  { top: 52px; left: 0; }
  .tc-right { top: 52px; right: 0; }
  .tc-down  { bottom: 0; left: 52px; }
  .tc-dpad::after { top: 58px; left: 58px; width: 40px; height: 40px; }
  .tc-action { width: 72px; height: 72px; font-size: 28px; }
  .tc-actions { bottom: 38px; right: 20px; }
}
