* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: #f1f5f9;
  color: #0f172a;
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom) 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 20px;
  background: radial-gradient(900px 320px at 20% 0%, #2563eb 0%, #0b2a5b 55%, #071a36 100%);
  color: #ffffff;
  box-shadow: 0 18px 45px rgba(2, 6, 23, 0.25);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background: rgba(255,255,255,0.95);
  object-fit: contain;
  padding: 6px;
}

.brand-text { min-width: 0; }
.brand-title { font-weight: 950; letter-spacing: 0.2px; font-size: 18px; line-height: 1.15; }
.brand-subtitle {
  font-size: 13px;
  opacity: 0.9;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  line-height: 1.25;
}

body[data-page="photo"] .brand-subtitle,
body[data-page="tf"] .brand-subtitle {
  display: none;
}

.icon-btn {
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(15, 23, 42, 0.25);
  color: #ffffff;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  font-size: 20px;
  font-weight: 950;
}

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
}

.panel {
  background: rgba(255,255,255,0.96);
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 18px;
  padding: 12px;
  box-shadow: 0 18px 45px rgba(2, 6, 23, 0.25);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-title {
  font-weight: 950;
  color: #0b2a5b;
  font-size: 16px;
  margin-bottom: 10px;
}

.panel-head .panel-title { margin-bottom: 0; }

.panel-subtitle {
  margin-top: 12px;
  font-weight: 950;
  color: #0b2a5b;
  font-size: 14px;
  margin-bottom: 10px;
}

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

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

#songLevelChips {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.chip {
  border: 1px solid #e2e8f0;
  background: #ffffff;
  color: #0f172a;
  border-radius: 999px;
  padding: 12px 14px;
  font-weight: 950;
  font-size: 14px;
  text-align: center;
}

.chip.active {
  border-color: rgba(37, 99, 235, 0.55);
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.22);
}

.skills-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.overview-card {
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,0.96) 0%, rgba(241,245,249,0.96) 100%);
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.overview-title {
  font-weight: 950;
  color: #0f172a;
  font-size: 15px;
}

.overview-level {
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.10);
  color: #0b2a5b;
  font-weight: 950;
  font-size: 13px;
}

.ring {
  width: 76px;
  height: 76px;
  border-radius: 999px;
  background: conic-gradient(#2563eb 0deg, rgba(226,232,240,0.9) 0deg);
  display: grid;
  place-items: center;
}

.ring > div {
  width: 62px;
  height: 62px;
  border-radius: 999px;
  background: rgba(255,255,255,0.98);
  display: grid;
  place-items: center;
  border: 1px solid rgba(226, 232, 240, 0.9);
}

.ring strong {
  font-size: 18px;
  color: #0b2a5b;
}

.radar {
  width: 100%;
  height: 130px;
  display: block;
}

.skill-card {
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,0.95) 0%, rgba(248,250,252,0.96) 100%);
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 10px;
  align-items: center;
}

.skill-title {
  font-weight: 950;
  color: #0f172a;
  font-size: 14px;
  line-height: 1.15;
}

.skill-score {
  margin-top: 6px;
  font-weight: 950;
  font-size: 26px;
  color: #0b2a5b;
  line-height: 1;
}

.skill-meta {
  margin-top: 6px;
  font-size: 13px;
  color: #64748b;
}

.skill-bar {
  margin-top: 10px;
  height: 10px;
  border-radius: 999px;
  background: rgba(226, 232, 240, 0.9);
  overflow: hidden;
}

.skill-bar > div {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #22c55e 0%, #16a34a 100%);
  width: 0%;
}

.spark {
  width: 120px;
  height: 44px;
  display: block;
}

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

.group-card {
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 18px;
  background: #ffffff;
  padding: 10px 12px;
}

.group-title {
  font-weight: 950;
  color: #0f172a;
  font-size: 13px;
}

.group-score {
  margin-top: 6px;
  font-weight: 950;
  font-size: 20px;
  color: #0b2a5b;
  line-height: 1;
}

.group-bar {
  margin-top: 10px;
  height: 8px;
  border-radius: 999px;
  background: rgba(226, 232, 240, 0.9);
  overflow: hidden;
}

.group-bar > div {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #60a5fa 0%, #2563eb 100%);
  width: 0%;
}

.games-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.game-card {
  border: 1px solid #e2e8f0;
  border-radius: 18px;
  background: #ffffff;
  padding: 12px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.game-title { font-weight: 950; color: #0f172a; font-size: 18px; }
.game-sub { font-size: 13px; color: #64748b; line-height: 1.25; }
.game-emoji { font-size: 26px; line-height: 1; }

.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.primary-btn, .secondary-btn {
  width: 100%;
  border-radius: 999px;
  padding: 11px 14px;
  font-weight: 950;
  border: none;
  font-size: 15px;
}
.primary-btn { background: linear-gradient(180deg, #60a5fa 0%, #3b82f6 100%); color: #ffffff; }
.secondary-btn { background: #ffffff; color: #0f172a; border: 1px solid #e2e8f0; }

.q-card {
  border: 1px solid #e2e8f0;
  border-radius: 18px;
  overflow: hidden;
  background: #ffffff;
}

.q-img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  object-position: center;
  display: block;
  background: #f8fafc;
  max-height: 34vh;
}

.q-body { padding: 12px; }
.q-title { font-weight: 950; color: #0f172a; font-size: 18px; line-height: 1.15; }
.q-meta { margin-top: 8px; font-size: 14px; color: #64748b; display: flex; gap: 10px; flex-wrap: wrap; }
.options { display: grid; gap: 8px; margin-top: 10px; }
.option-btn {
  width: 100%;
  border-radius: 14px;
  padding: 14px 14px;
  font-weight: 950;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  text-align: left;
  font-size: 16px;
}

.option-btn.selected {
  background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%);
  color: #ffffff;
  border-color: rgba(37, 99, 235, 0.65);
}

.result-text {
  margin-top: 10px;
  font-weight: 950;
  font-size: 15px;
}

.result-text.ok { color: #16a34a; }
.result-text.bad { color: #dc2626; }

body[data-page="photo"] #viewPanel,
body[data-page="tf"] #viewPanel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body[data-page="song"] #viewPanel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body[data-page="photo"] #viewBody,
body[data-page="tf"] #viewBody {
  flex: 1;
  min-height: 0;
  display: flex;
}

body[data-page="song"] #viewBody {
  flex: 1;
  min-height: 0;
  display: flex;
}

body[data-page="photo"] #viewBody > .q-card,
body[data-page="tf"] #viewBody > .q-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body[data-page="song"] #viewBody > .audio-match {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body[data-page="photo"] #viewBody > .q-card > .q-body,
body[data-page="tf"] #viewBody > .q-card > .q-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
}

body[data-page="photo"] .options {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

body[data-page="photo"] .option-btn,
body[data-page="tf"] .option-btn {
  padding: 12px 12px;
  font-size: 15px;
}

body.preview .q-img {
  max-height: 180px;
  aspect-ratio: 16 / 9;
}

body.preview .q-title {
  font-size: 16px;
}

body.preview .q-meta {
  font-size: 13px;
  margin-top: 6px;
}

body.preview .options {
  margin-top: 8px;
  gap: 8px;
}

body.preview .option-btn {
  padding: 10px 10px;
  font-size: 14px;
}

body.preview .result-text {
  margin-top: 8px;
  font-size: 14px;
}

body.preview[data-page="photo"] #viewBody {
  display: block;
}

body.preview[data-page="photo"] #viewBody > .q-card {
  display: block;
}

body.preview[data-page="photo"] #viewBody > .q-card > .q-body {
  overflow: visible;
  padding-bottom: 12px;
}

body[data-page="photo"] .primary-btn,
body[data-page="photo"] .secondary-btn,
body[data-page="tf"] .primary-btn,
body[data-page="tf"] .secondary-btn {
  padding: 10px 12px;
  font-size: 14px;
}

.audio-match {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.audio-match-head {
  text-align: center;
  padding: 6px 6px 0;
}

.audio-match-level {
  font-weight: 950;
  color: #0b2a5b;
  font-size: 14px;
}

.audio-match-title {
  margin-top: 6px;
  font-weight: 950;
  font-size: 22px;
  color: #0f172a;
}

.audio-match-sub {
  margin-top: 6px;
  font-size: 14px;
  color: #475569;
  line-height: 1.4;
}

.audio-match-grid {
  display: grid;
  grid-template-columns: 92px 1fr 1.25fr;
  gap: 10px;
  align-items: start;
}

.audio-col, .slot-col, .target-col {
  display: grid;
  grid-auto-rows: 1fr;
  gap: 10px;
}

.audio-tile {
  border: 1px solid rgba(203, 213, 225, 0.9);
  border-radius: 14px;
  background: #fde047;
  height: 86px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 10px 24px rgba(2, 6, 23, 0.12);
  touch-action: none;
  user-select: none;
}

.audio-tile.ok {
  background: #bbf7d0;
  border-color: rgba(34, 197, 94, 0.45);
}

.audio-tile:active {
  transform: scale(0.99);
}

.audio-play {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: none;
  background: rgba(15, 23, 42, 0.9);
  color: #ffffff;
  font-size: 18px;
  font-weight: 950;
}

.drop-slot {
  border: 2px dashed #cbd5e1;
  border-radius: 14px;
  background: #f8fafc;
  height: 86px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-weight: 950;
}

.drop-slot.ok {
  border-style: solid;
  border-color: rgba(34, 197, 94, 0.55);
  background: rgba(34, 197, 94, 0.10);
  color: #16a34a;
}

.drop-slot.bad {
  border-style: solid;
  border-color: rgba(239, 68, 68, 0.55);
  background: rgba(239, 68, 68, 0.10);
  color: #dc2626;
}

.target-card {
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  overflow: hidden;
  background: #ffffff;
  height: 86px;
  display: flex;
  flex-direction: column;
}

.target-card img {
  width: 100%;
  height: 58px;
  object-fit: contain;
  display: block;
  background: #f8fafc;
  cursor: pointer;
}

.target-name {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  font-weight: 950;
  color: #0f172a;
  font-size: 12px;
  line-height: 1.05;
  text-align: center;
  overflow: hidden;
  display: -webkit-box;
  line-clamp: 2;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.img-viewer-overlay {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(8px);
}

.img-viewer-card {
  width: min(960px, 100%);
  height: min(82vh, 760px);
  background: rgba(255,255,255,0.96);
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(2, 6, 23, 0.35);
  position: relative;
  overflow: hidden;
  display: flex;
}

.img-viewer-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #0b1220;
}

.img-viewer-caption {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(226, 232, 240, 0.92);
  color: #0f172a;
  font-weight: 950;
  text-align: center;
  box-shadow: 0 10px 22px rgba(2, 6, 23, 0.22);
}

.img-viewer-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid rgba(226, 232, 240, 0.9);
  background: rgba(255,255,255,0.92);
  color: #0f172a;
  font-weight: 950;
  font-size: 18px;
}

.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  width: 92px;
  height: 86px;
  border-radius: 14px;
  background: #fde047;
  border: 1px solid rgba(203, 213, 225, 0.9);
  box-shadow: 0 18px 40px rgba(2, 6, 23, 0.25);
  z-index: 999999;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drag-ghost .audio-play {
  pointer-events: none;
}

.audio-tile.done {
  opacity: 0.35;
}


.months {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.month-btn {
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  padding: 10px 0;
  font-weight: 950;
  font-size: 12px;
}
.month-btn.on { background: rgba(37, 99, 235, 0.10); border-color: rgba(37, 99, 235, 0.35); color: #1e3a8a; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(2,6,23,0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom) 16px;
  z-index: 99999;
}

.overlay.skills-overlay {
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.skills-sheet {
  width: 100%;
  max-width: 980px;
  height: calc(100vh - env(safe-area-inset-top));
  background: #f8fafc;
  border-radius: 18px 18px 0 0;
  border: 1px solid rgba(226, 232, 240, 0.9);
  box-shadow: 0 24px 60px rgba(2, 6, 23, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.skills-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 12px 12px;
  background: rgba(255,255,255,0.96);
  border-bottom: 1px solid rgba(226, 232, 240, 0.9);
}

.skills-sheet-title {
  font-weight: 950;
  color: #0b2a5b;
  font-size: 16px;
}

.skills-sheet-body {
  padding: 12px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
}

.overlay.species-overlay {
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.species-sheet {
  width: 100%;
  max-width: 980px;
  height: calc(100vh - env(safe-area-inset-top));
  background: #f8fafc;
  border-radius: 18px 18px 0 0;
  border: 1px solid rgba(226, 232, 240, 0.9);
  box-shadow: 0 24px 60px rgba(2, 6, 23, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.species-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 12px 12px;
  background: rgba(255,255,255,0.96);
  border-bottom: 1px solid rgba(226, 232, 240, 0.9);
}

.species-sheet-title {
  font-weight: 950;
  color: #0b2a5b;
  font-size: 16px;
}

.species-sheet-body {
  padding: 12px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
}

.species-sheet-img {
  width: 100%;
  max-height: 36vh;
  object-fit: contain;
  background: #ffffff;
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 18px;
}

.species-sheet-meta {
  margin-top: 10px;
  font-size: 14px;
  color: #64748b;
  font-style: italic;
}

.species-sheet-h {
  margin-top: 12px;
  font-weight: 950;
  color: #0f172a;
  font-size: 14px;
}

.species-sheet-p {
  margin-top: 6px;
  color: #334155;
  font-size: 14px;
  line-height: 1.55;
}

.species-sheet-actions {
  margin-top: 12px;
}

.modal {
  width: min(520px, 100%);
  background: #ffffff;
  border-radius: 22px;
  border: 1px solid #e2e8f0;
  padding: 14px;
  box-shadow: 0 30px 80px rgba(2, 6, 23, 0.45);
}

.modal-title { font-weight: 950; font-size: 16px; color: #0b2a5b; }
.modal-body { margin-top: 10px; color: #334155; line-height: 1.55; font-size: 14px; }
.modal-actions { display: grid; gap: 10px; margin-top: 12px; }

@media (min-width: 720px) {
  .skills-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .skill-card { grid-template-columns: 1fr; }
  .spark { width: 100%; height: 46px; }
  .overview-card { grid-template-columns: 1fr 220px; }
  .radar { width: 220px; height: 150px; }
  .group-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .games-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .q-img { max-height: 420px; }
}

@media (max-width: 380px) {
  .months { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  #songLevelChips { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
