/* styles.css — Japanska trädgården
   Inspirerad av Capy-ramverket (game-shell, top-bar, pills, speech bubble) */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #2d4d1a 0%, #4e7a2d 18%, #a7d8f0 42%, #e8f5d9 100%);
}

/* ── GAME SHELL ─────────────────────────────────────────── */
.game-shell {
  max-width: 980px;
  margin: 0 auto;
  padding: 12px 10px 30px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
@media (max-width: 480px) {
  .game-shell { padding: 8px 5px 20px; gap: 8px; }
}

/* ── TOP BAR ────────────────────────────────────────────── */
.top-bar {
  background: rgba(255,255,255,0.93);
  border-radius: 16px;
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.18);
  flex-shrink: 0;
}
@media (max-width: 480px) {
  .top-bar { padding: 8px 10px; gap: 8px; }
}
.top-bar .title-group { display: flex; align-items: center; gap: 12px; }
.top-bar h1 {
  font-size: clamp(15px, 3.5vw, 20px);
  color: #1a3c1a;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.top-bar h1 img { height: 28px; }
.top-bar .back { font-size: 13px; color: #3498db; text-decoration: none; font-weight: 700; }

.pills { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pill {
  background: #f1f5f1;
  border: 1px solid #c8d8c8;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 700;
  color: #2d5a2d;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.pill.pill-gold { background: #fff8dc; border-color: #ffd700; }
.pill.pill-replay {
  background: #e8f0fe;
  border-color: #90caf9;
  color: #1a3c6e;
  cursor: pointer;
  font-family: inherit;
}
.pill.pill-replay:hover { background: #d0e3fc; }

/* ── MODE SWITCH ────────────────────────────────────────── */
.mode-switch {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.mode-btn {
  flex: 1;
  background: rgba(255,255,255,0.9);
  border: 2px solid #c8d8c8;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  color: #2d5a2d;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}
.mode-btn:hover { transform: translateY(-1px); }
.mode-btn.active {
  background: #2d5a2d;
  color: #fff;
  border-color: #1f4620;
}

/* ── MASKOT SPEECH BUBBLE ───────────────────────────────── */
@keyframes capy-flash {
  0%   { background: rgba(255,255,255,0.95); box-shadow: 0 2px 12px rgba(0,0,0,0.12); border-color: #a5d6a7; }
  25%  { background: rgba(255,220,220,0.98); box-shadow: 0 4px 24px rgba(220,0,0,0.35); border-color: #e74c3c; }
  60%  { background: rgba(255,220,220,0.98); box-shadow: 0 4px 24px rgba(220,0,0,0.35); border-color: #e74c3c; }
  100% { background: rgba(255,255,255,0.95); box-shadow: 0 2px 12px rgba(0,0,0,0.12); border-color: #a5d6a7; }
}
@keyframes capy-success {
  0%   { background: rgba(255,255,255,0.95); border-color: #a5d6a7; }
  30%  { background: rgba(210,250,210,0.98); border-color: #2ecc71; box-shadow: 0 4px 24px rgba(46,204,113,0.4); }
  100% { background: rgba(255,255,255,0.95); border-color: #a5d6a7; }
}
.capy-bubble {
  background: rgba(255,255,255,0.95);
  border: 2px solid #a5d6a7;
  border-radius: 16px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.12);
  flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s, border-color 0.3s;
}
.capy-bubble img#capy-avatar { height: 36px; flex-shrink: 0; }
.capy-bubble.flash { animation: capy-flash 1.4s ease-in-out; }
.capy-bubble.success { animation: capy-success 1s ease-in-out; }
.capy-bubble-text-wrap {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
#capy-speech { font-size: 13px; color: #2d5a2d; font-style: italic; font-weight: 600; line-height: 1.4; flex: 1 1 180px; }
.jp-word {
  font-size: clamp(22px, 5vw, 32px);
  font-weight: 800;
  color: #1a3c1a;
  flex-shrink: 0;
}
.jp-word:empty { display: none; }
#quiz-skip-btn {
  background: #2d5a2d;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 8px 16px;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
  display: none;
}
#quiz-skip-btn.show { display: inline-block; }
#quiz-skip-btn:hover { background: #1f4620; }

/* ── GLOSOR (vokabulärlista) ─────────────────────────────── */
.glosor-wrap {
  display: none;
}
.glosor-wrap.show {
  display: block;
}
.glosor-card {
  background: rgba(255,255,255,0.96);
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: 0 6px 28px rgba(0,0,0,0.18);
  border-left: 6px solid #d32f2f;
}
.glosor-card-title {
  font-size: 15px;
  font-weight: 800;
  color: #1a3c1a;
  margin-bottom: 12px;
}
.glosor-table {
  width: 100%;
  border-collapse: collapse;
}
.glosor-table th {
  text-align: left;
  padding: 8px 10px;
  background: #ffebee;
  color: #c62828;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.glosor-table td {
  padding: 9px 10px;
  font-size: 14px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}
.glosor-table tr:last-child td { border-bottom: none; }
.glosor-table tr:hover td { background: #fff8f0; }
.glosor-sv { font-weight: 700; color: #2c3e50; }
.glosor-jp { font-size: 18px; font-weight: 800; color: #1a3c1a; }
.glosor-pron { color: #888; font-style: italic; font-size: 13px; }
.glosor-table tr.is-found .glosor-sv::after {
  content: " ✔️";
}
.glosor-speak-btn {
  background: #3498db;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.glosor-speak-btn:hover { background: #2980b9; }
@media (max-width: 600px) {
  .glosor-table th:nth-child(3), .glosor-table td:nth-child(3) { display: none; }
  .glosor-card { padding: 12px 10px; }
}

/* ── GLOSOR: Start-knapp ─────────────────────────────────── */
.glosor-start-area {
  text-align: center;
  margin-top: 16px;
}
.glosor-btn-start {
  background: #d32f2f;
  color: #fff;
  border: none;
  padding: 13px 28px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}
.glosor-btn-start:hover { background: #b71c1c; transform: translateY(-2px); }

/* ── GLOSOR: Testsektion ─────────────────────────────────── */
.glosor-test-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.glosor-card-alt { border-left-color: #1a3c1a; }
.glosor-q-block {
  padding: 12px 0;
  border-bottom: 1px solid #f5f5f5;
}
.glosor-q-block:last-of-type { border-bottom: none; }
.glosor-q-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.glosor-q-label {
  font-size: 18px;
  font-weight: 800;
  color: #1a3c1a;
  flex: 1;
}
.glosor-q-label-pron {
  font-size: 13px;
  font-weight: 600;
  font-style: italic;
  color: #777;
}
.glosor-hint-btn {
  background: #f8f9fa;
  border: 1px solid #ddd;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 14px;
  color: #7f8c8d;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: 0.2s;
}
.glosor-hint-btn:hover { background: #d32f2f; color: #fff; border-color: #d32f2f; }
.glosor-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.glosor-opt-btn {
  background: #f8f9fa;
  border: 2px solid #ddd;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  transition: 0.18s;
  font-family: inherit;
  color: #333;
  width: 100%;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.glosor-opt-main {
  font-size: 17px;
  font-weight: 800;
}
.glosor-opt-pron-row {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.glosor-opt-pron {
  font-size: 11px;
  font-weight: 600;
  font-style: italic;
  opacity: 0.75;
}
.glosor-opt-speak {
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.8;
  transition: transform 0.15s, opacity 0.15s;
}
.glosor-opt-speak:hover { opacity: 1; transform: scale(1.2); }
.glosor-opt-btn:hover:not(:disabled) { border-color: #d32f2f; background: #ffebee; }
.glosor-opt-btn.selected {
  background: #ffc107 !important;
  color: #3d2b00 !important;
  border-color: #e0a800;
  font-weight: bold;
  box-shadow: 0 0 0 3px rgba(255,193,7,0.35);
}
.glosor-opt-btn.correct { background: #22c55e !important; color: #fff !important; border-color: #16a34a !important; font-weight: bold !important; box-shadow: 0 0 0 3px rgba(34,197,94,0.3) !important; }
.glosor-opt-btn.wrong { background: #ef4444 !important; color: #fff !important; border-color: #dc2626 !important; font-weight: bold !important; }
.glosor-opt-btn:disabled { cursor: default; }

.glosor-submit-area {
  background: rgba(255,255,255,0.96);
  padding: 20px;
  border-radius: 15px;
  border-top: 5px solid #2ecc71;
  text-align: center;
  box-shadow: 0 6px 28px rgba(0,0,0,0.18);
}
.glosor-progress-text { font-size: 13px; color: #666; margin: 0 0 10px; }
.glosor-btn-send {
  background: #2ecc71;
  color: #fff;
  border: none;
  padding: 15px;
  width: 100%;
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
  font-weight: bold;
  transition: 0.2s;
}
.glosor-btn-send:hover { background: #27ae60; transform: translateY(-2px); }
.glosor-feedback {
  display: none;
  margin-top: 14px;
  padding: 12px;
  background: #fff3e0;
  border-radius: 10px;
  font-size: 13px;
  text-align: left;
}
.glosor-feedback ul { margin: 6px 0 0 18px; padding: 0; }
.glosor-result { display: none; text-align: center; margin-top: 16px; }
.glosor-score-big { font-size: 2.6rem; font-weight: bold; color: #2ecc71; }
.glosor-result-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 14px;
}
.glosor-result-actions button, .glosor-result-actions a {
  padding: 10px 18px;
  cursor: pointer;
  font-size: 14px;
  border: none;
  border-radius: 8px;
  font-weight: bold;
  text-decoration: none;
  display: inline-block;
}
.glosor-retry-btn { background: #e91e63; color: #fff; }
.glosor-back-link { background: #3498db; color: #fff; }
@media (max-width: 480px) {
  .glosor-options { grid-template-columns: 1fr; }
  .glosor-q-label { font-size: 16px; }
}

/* ── BOARD WRAP (spelplan) ──────────────────────────────── */
.board-wrap {
  position: relative;
  background: rgba(255,255,255,0.9);
  border-radius: 14px;
  padding: 8px;
  box-shadow: 0 6px 28px rgba(0,0,0,0.22);
  overflow: hidden;
  touch-action: none;
}
.board-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 10px;
  background: #cfe8b0;
}
.board-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  transform-origin: 50% 50%;
  transition: transform 0.6s cubic-bezier(.25,.8,.3,1);
  will-change: transform;
}
#board-img {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

/* Klickbara hotspots ovanpå bilden */
.hotspot {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 9%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  cursor: pointer;
  background: rgba(255,255,255,0.01);
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
.hotspot:hover, .hotspot:focus-visible {
  background: rgba(255,255,0,0.18);
  border-color: rgba(255,215,0,0.7);
  outline: none;
}
.hotspot.found { border-color: rgba(46,204,113,0.5); }

/* ── IDLE PULSE – visar att objektet går att klicka på ──── */
@keyframes idle-pulse {
  0%   { transform: scale(1);     opacity: 0.55; box-shadow: 0 0 0 0 rgba(255,215,0,0.45); }
  50%  { transform: scale(1.06);  opacity: 0.9;  box-shadow: 0 0 0 6px rgba(255,215,0,0); }
  100% { transform: scale(1);     opacity: 0.55; box-shadow: 0 0 0 0 rgba(255,215,0,0); }
}
.hotspot .pulse-marker {
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.55) 0%, rgba(255,215,0,0.35) 55%, rgba(255,215,0,0) 80%);
  border: 2px solid rgba(255,215,0,0.6);
  pointer-events: none;
  animation: idle-pulse 1.8s ease-in-out infinite;
  transition: opacity 0.2s;
}
/* Pausa pulsering vid hover/fokus, när objektet är hittat, eller tillfälligt "klickat" */
.hotspot:hover .pulse-marker,
.hotspot:focus-visible .pulse-marker,
.hotspot.found .pulse-marker,
.hotspot.clicked .pulse-marker {
  animation-play-state: paused;
  opacity: 0;
}
.hotspot .check-mark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(16px, 3vw, 26px);
  opacity: 0;
  transform: scale(0.3);
  transition: none;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}
.hotspot.found .check-mark {
  opacity: 1;
  transform: scale(1);
  animation: pop-check 0.4s cubic-bezier(.34,1.56,.64,1);
}
@keyframes pop-check {
  0% { transform: scale(0.2); opacity: 0; }
  60% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ── KOORDINAT-VERKTYG (tillfälligt debug-läge) ─────────── */
.coord-marker {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(231, 76, 60, 0.85);
  border: 2px solid #fff;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 50;
  box-shadow: 0 0 6px rgba(0,0,0,0.5);
  animation: coord-fade 4s ease forwards;
}
.coord-marker .coord-label {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 4px;
  white-space: nowrap;
}
@keyframes coord-fade {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

/* Screen shake vid fel svar */
.board-wrap.shake { animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(4px); }
}

/* ── OBJECT POPUP CARD ──────────────────────────────────── */
.popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 16px;
}
.popup-overlay.show { display: flex; }
.popup-card {
  background: #fff;
  border-radius: 20px;
  padding: 24px 26px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  animation: popIn 0.3s ease both;
}
@keyframes popIn {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.popup-card .jp-big { font-size: clamp(34px, 9vw, 48px); font-weight: 800; color: #1a3c1a; margin: 4px 0; }
.popup-card .sv-name { font-size: 18px; font-weight: 700; color: #333; margin-bottom: 4px; }
.popup-card .pron-text { font-size: 14px; color: #777; font-style: italic; margin-bottom: 14px; }
.popup-card .check-badge { font-size: 28px; margin-bottom: 6px; }
.popup-card button {
  background: #2d5a2d;
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 10px 26px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 6px;
}
.popup-card button:hover { background: #1f4620; }
.popup-card .speak-btn {
  background: #3498db;
  margin-right: 8px;
}
.popup-card .speak-btn:hover { background: #2980b9; }
.popup-card .btn-row { display: flex; justify-content: center; gap: 8px; margin-top: 10px; }

/* ── DIPLOMA / CONFETTI ─────────────────────────────────── */
.diploma-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 400;
  padding: 20px;
}
.diploma-overlay.show { display: flex; }
.diploma-box {
  background: #fffdf5;
  border: 6px solid #ffd700;
  border-radius: 20px;
  padding: 36px 28px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 25px 70px rgba(0,0,0,0.4);
  animation: popIn 0.4s ease both;
}
.diploma-box .trophy { font-size: 60px; margin-bottom: 10px; }
.diploma-box h2 { color: #1a3c1a; margin: 0 0 8px; font-size: 24px; }
.diploma-box p { color: #555; font-size: 14px; margin: 6px 0 18px; }
.diploma-box button {
  background: #2d5a2d;
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 26px;
  font-weight: 700;
  cursor: pointer;
}
.confetti-piece {
  position: fixed;
  top: -10px;
  width: 10px;
  height: 14px;
  opacity: 0.9;
  z-index: 410;
  pointer-events: none;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(540deg); opacity: 0.3; }
}

/* ── BOARD CONTROLS (zoom out / help) ──────────────────── */
.board-controls {
  position: absolute;
  bottom: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  z-index: 60;
  pointer-events: none;
}
.board-controls button {
  background: rgba(255,255,255,0.92);
  border: 2px solid #a5d6a7;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  /* .board-wrap sätter touch-action:none för panorering av bilden — utan
     denna rad "ärver" knapparna det och tar inte emot klick/tryck korrekt
     på pekskärmar/pekplattor. */
  touch-action: manipulation;
  pointer-events: auto;
  position: relative;
}
.board-controls button:hover { background: #d4edda; }
#coord-tool-btn { display: none; }
#zoom-out-btn { display: none; }
#coord-tool-btn.active {
  background: #e74c3c;
  border-color: #c0392b;
  color: #fff;
}

.footer-note {
  text-align: center;
  font-size: 11px;
  color: rgba(255,255,255,0.8);
  margin-top: 4px;
}

/* ── KOORDINAT-MAPPNINGSPANEL (debug-läge) ──────────────── */
.coord-panel {
  position: fixed;
  top: 12px;
  right: 12px;
  width: 300px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  background: rgba(20,20,20,0.95);
  color: #fff;
  border: 2px solid #e74c3c;
  border-radius: 14px;
  padding: 12px 14px;
  z-index: 600;
  font-size: 12px;
  display: none;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  overflow: hidden;
}
.coord-panel.show { display: flex; }
.coord-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}
.coord-panel-header button {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  opacity: 0.7;
}
.coord-panel-header button:hover { opacity: 1; }
.coord-panel-hint {
  font-size: 11px;
  color: #ddd;
  line-height: 1.4;
  margin: 0;
}
.coord-panel-current {
  background: rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 6px 8px;
  font-weight: 700;
}
.coord-panel-current #coord-current-label { color: #ffd700; }
.coord-panel-actions {
  display: flex;
  gap: 6px;
}
.coord-panel-actions button {
  flex: 1;
  background: #2d5a2d;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 6px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.coord-panel-actions button:hover { background: #1f4620; }
#coord-item-select {
  background: #111;
  color: #fff;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 4px;
  font-size: 11px;
  flex: 1 1 auto;
  min-height: 140px;
}
#coord-item-select option.mapped { color: #8fdc8f; }
#coord-item-select option.current { background: #e74c3c; color: #fff; }
#coord-export-output {
  background: #111;
  color: #9fe29f;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 6px;
  font-family: "Consolas", monospace;
  font-size: 10px;
  height: 90px;
  resize: vertical;
}
