:root {
  --bg: #0f1220;
  --panel: #1a1f36;
  --panel-2: #232a4a;
  --accent: #ff2e7e;
  --accent-2: #3ddc97;
  --text: #f2f4ff;
  --muted: #9aa3c7;
  --cell: 104px;
  --header: 132px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(circle at 50% -10%, #262c52 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

header { text-align: center; margin: 28px 16px 8px; }

h1 {
  margin: 0;
  font-size: clamp(28px, 6vw, 44px);
  letter-spacing: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline { color: var(--muted); margin: 6px 0 0; font-size: 15px; }
.reset-note { color: var(--accent-2); margin: 6px 0 0; font-size: 12.5px; }

/* version switch (Phoenix / Phoenix 2) */
.verswitch {
  display: flex;
  justify-content: center;
  gap: 4px;
  width: max-content;
  margin: 12px auto 0;
  background: var(--panel);
  border: 1px solid var(--panel-2);
  border-radius: 12px;
  padding: 4px;
}
.verswitch button {
  background: transparent;
  color: var(--muted);
  padding: 8px 18px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 700;
}
.verswitch button.active {
  background: var(--accent);
  color: #fff;
}
.verswitch button:not(.active):hover { color: var(--text); background: var(--panel-2); }
.verswitch button:disabled { opacity: .35; cursor: not-allowed; }

/* language switch */
.langswitch {
  position: absolute;
  top: 16px; right: 16px;
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 700; color: var(--muted);
}
.lang-lbl.active { color: var(--text); }
.switch { position: relative; display: inline-block; width: 42px; height: 22px; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider-track {
  position: absolute; inset: 0;
  background: var(--panel-2); border-radius: 22px; transition: background .15s;
}
.slider-track::before {
  content: ''; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px;
  background: var(--accent); border-radius: 50%; transition: transform .15s;
}
.switch input:checked + .slider-track::before { transform: translateX(20px); }

main { width: 100%; max-width: 640px; padding: 12px 16px 40px; }

.status {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  margin: 10px 4px 14px;
  color: var(--muted);
  transition: color .1s;
}
.status.wrong { color: var(--accent); }

/* Pump-It-Up-style life bar */
.life-wrap { display: flex; align-items: center; gap: 10px; }
.lifebar {
  width: 150px; height: 15px;
  background: #10131f;
  border: 1px solid var(--panel-2);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.6);
}
.life-fill {
  height: 100%;
  width: 100%;
  /* fixed gradient across the full bar: red (danger) at left, green at right.
     the bar depletes from the right, so low life shows red. */
  background: linear-gradient(90deg, #ff2e3e 0%, #ff8a2e 30%, #ffd23f 55%, #3ddc97 100%);
  background-size: 150px 100%;
  background-position: left center;
  transition: width .3s ease;
  border-radius: 0 6px 6px 0;
}
.life-fill.low { animation: lifepulse .8s ease-in-out infinite; }
.life-fill.empty { width: 0; }
@keyframes lifepulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }
.life-text { font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: 1px; }

/* puzzle code loader */
.code-row { display: flex; align-items: center; gap: 8px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
#codeInput {
  font: inherit; padding: 8px 10px; border-radius: 8px;
  border: 2px solid var(--panel-2); background: var(--bg); color: var(--text);
  width: 240px; max-width: 60vw;
}
#codeInput:focus { outline: none; border-color: var(--accent-2); }
#loadCode { padding: 8px 16px; }
.code-msg { color: var(--accent); font-size: 13px; }

/* puzzle code in endscreen */
.code-box {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--bg); border: 1px solid var(--panel-2); border-radius: 10px;
  padding: 8px 10px; margin: 4px 0 10px;
}
.code-label { color: var(--muted); font-size: 12px; }
.code-val { flex: 1; min-width: 120px; font: 12px/1.3 monospace; color: var(--accent-2); word-break: break-all; }
.code-copy { padding: 6px 10px; font-size: 12px; background: var(--panel-2); color: var(--text); }
.share-link {
  display: block; margin: 0 0 10px;
  color: var(--accent-2); font-size: 12px; word-break: break-all; text-align: center;
}

.grid {
  display: grid;
  grid-template-columns: var(--header) repeat(3, var(--cell));
  grid-auto-rows: minmax(var(--cell), auto);
  gap: 8px;
  justify-content: center;
}

.cell {
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
  position: relative;
}

.cell.corner {
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 2px;
  font-weight: 700;
}

.cell.header {
  background: var(--panel-2);
  padding: 8px 8px 8px 8px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
}
.cell.header .hlabel { padding: 0 6px; }
.cell.header .help {
  position: absolute;
  top: 4px; right: 5px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.cell.header .help:hover { color: var(--accent-2); }
.cell.header .help:active { color: var(--accent); }

/* help tooltip popup (tap/click) */
.tip {
  position: fixed;
  z-index: 50;
  max-width: 240px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px; font-weight: 500; line-height: 1.35;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--bg);
  box-shadow: 0 8px 24px rgba(0,0,0,.55);
  pointer-events: none;
}
.tip.hidden { display: none; }

.cell.play {
  background: var(--panel);
  cursor: pointer;
  font-size: 34px;
  color: var(--muted);
  border: 2px solid transparent;
  transition: border-color .15s, background .15s;
}
.cell.play:hover { border-color: var(--accent); background: var(--panel-2); }
.cell.play.filled { cursor: default; font-size: 0; }
.cell.play.empty  { cursor: default; }

.cell.play img { width: 100%; height: 100%; object-fit: cover; }

.caption {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,.7);
  color: #fff;
  font-size: 11px;
  padding: 3px 4px;
  line-height: 1.2;
}

.cell.play.study-cell {
  cursor: pointer;
  font-size: 26px;
  color: var(--accent-2);
  border-color: var(--panel-2);
}
.cell.play.study-cell:hover { border-color: var(--accent-2); background: var(--panel-2); }
.result.study { cursor: default; }
.result.study:hover { background: transparent; }

.controls { display: flex; gap: 12px; justify-content: center; margin-top: 20px; }

button {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  padding: 11px 20px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}
button.secondary { background: var(--panel-2); color: var(--text); }
button:hover { filter: brightness(1.1); }

.loading { text-align: center; color: var(--muted); margin-top: 24px; }

/* overlay */
.overlay {
  position: fixed; inset: 0;
  background: rgba(6,8,18,.8);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 8vh 16px;
  z-index: 10;
}
.overlay.hidden { display: none; }

.dialog {
  background: var(--panel);
  border-radius: 16px;
  padding: 22px;
  width: 100%; max-width: 440px;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}

.close {
  position: absolute; top: 10px; right: 12px;
  background: transparent; color: var(--muted);
  font-size: 26px; line-height: 1; padding: 4px 8px;
}
.close:hover { color: var(--text); }

.dialog-prompt {
  margin: 0 0 14px;
  font-weight: 700;
  color: var(--accent-2);
  font-size: 15px;
  padding-right: 30px;
}

#search {
  width: 100%;
  font: inherit;
  padding: 11px 12px;
  border-radius: 10px;
  border: 2px solid var(--panel-2);
  background: var(--bg);
  color: var(--text);
}
#search:focus { outline: none; border-color: var(--accent); }

.results { list-style: none; margin: 12px 0 0; padding: 0; max-height: 46vh; overflow-y: auto; }
.result {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 8px; cursor: pointer;
}
.result:hover { background: var(--panel-2); }
.result img { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; }
.result span { flex: 1; }
.result small { color: var(--muted); }
.result.used { opacity: .4; cursor: not-allowed; }

footer { color: var(--muted); font-size: 12px; text-align: center; padding: 20px; }
footer a { color: var(--accent-2); }

/* endscreen */
.endscreen-dialog { max-width: 480px; max-height: 84vh; overflow-y: auto; }
.end-title { margin: 4px 0 4px; text-align: center; font-size: 26px; }
.end-version { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 10px; }
.emoji-grid {
  font-size: 30px; line-height: 1.15; text-align: center;
  margin: 0 0 12px; font-family: system-ui, sans-serif; letter-spacing: 2px;
}
.end-hint { text-align: center; color: var(--muted); font-size: 13px; margin: 12px 0 0; }

#shareBtn, .end-new { width: 100%; margin-top: 4px; }
.end-new { margin-top: 14px; background: var(--panel-2); color: var(--text); }

.share-area {
  width: 100%; height: 96px; margin-top: 10px; resize: none;
  background: var(--bg); color: var(--muted); border: 2px solid var(--panel-2);
  border-radius: 10px; padding: 8px; font: 13px/1.3 monospace;
}

.end-sub { margin: 20px 0 8px; font-size: 15px; color: var(--muted); }
.solution { display: flex; flex-direction: column; gap: 8px; }
.sol-cell {
  background: var(--panel-2); border-radius: 10px; padding: 8px 10px;
  border-left: 4px solid var(--accent-2);
}
.sol-cell.miss { border-left-color: var(--accent); }
.sol-crit { font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.sol-crit span { color: var(--text); }
.sol-ans { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.sol-ans img { width: 34px; height: 34px; border-radius: 6px; object-fit: cover; }
.sol-ans span { flex: 1; font-weight: 600; }
.sol-ans em { color: var(--muted); font-style: normal; font-size: 12px; white-space: nowrap; }
.sol-ans.miss span { color: var(--accent); font-weight: 500; }

@media (max-width: 560px) {
  :root { --cell: 90px; --header: 84px; }
  header { margin: 12px 12px 8px; }
  /* move the language switch into the flow so it never overlaps the title */
  .langswitch { position: static; justify-content: flex-end; margin: 0 2px 8px; }
  h1 { font-size: 34px; }
  .grid {
    grid-template-columns: var(--header) repeat(3, 1fr);
    gap: 6px;
  }
  .cell.header { font-size: 10.5px; padding: 5px; }
  .cell.header .hlabel { padding: 0 10px 0 2px; }
  .cell.header .help { top: 3px; right: 3px; width: 20px; height: 20px; font-size: 13px; }
  .cell.play { font-size: 28px; }
  .cell.corner { font-size: 9px; }
  main { padding: 10px 10px 32px; }
  .emoji-grid { font-size: 26px; }
  .controls { flex-wrap: wrap; }
}

@media (max-width: 380px) {
  :root { --cell: 84px; --header: 78px; }
  .cell.header { font-size: 10px; }
}
