:root {
  --ink: #fff8e7;
  --dark: #140d27;
  --panel: rgba(20, 13, 39, 0.82);
  --panel-strong: rgba(31, 18, 57, 0.94);
  --line: rgba(255, 255, 255, 0.2);
  --cyan: #49e7ff;
  --mint: #67ffad;
  --yellow: #ffd75a;
  --pink: #ff4faf;
  --violet: #8a65ff;
  --danger: #ff6a5b;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  background: #130d28;
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button,
a,
.word-tile,
.sentence-token {
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: relative;
  min-height: 100vh;
  isolation: isolate;
  background:
    linear-gradient(90deg, rgba(13, 9, 30, 0.74), rgba(13, 9, 30, 0.36), rgba(13, 9, 30, 0.8)),
    url("assets/language-lab-bg.png") center / cover no-repeat;
}

.app::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 17% 24%, rgba(73, 231, 255, 0.26), transparent 27%),
    radial-gradient(circle at 83% 18%, rgba(255, 79, 175, 0.24), transparent 24%),
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: auto, auto, 46px 46px, 46px 46px;
  pointer-events: none;
}

.screen {
  min-height: 100vh;
  padding: clamp(14px, 2vw, 24px);
}

.hidden {
  display: none !important;
}

.start-screen,
.end-screen {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 460px);
  gap: clamp(18px, 3vw, 34px);
  align-items: center;
  width: min(1180px, 100%);
  margin: 0 auto;
}

.start-hero,
.end-panel,
.leaderboard-panel,
.control-panel,
.workbench,
.hud > div,
.hud-button {
  border: 3px solid #070411;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow), 7px 7px 0 #070411;
  backdrop-filter: blur(8px);
}

.start-hero {
  min-height: min(600px, calc(100vh - 48px));
  display: grid;
  align-content: end;
  overflow: hidden;
  padding: clamp(20px, 3.6vw, 42px);
  background:
    linear-gradient(180deg, rgba(20, 13, 39, 0.05), rgba(20, 13, 39, 0.9) 72%),
    url("assets/language-lab-bg.png") center / cover no-repeat;
}

.kicker {
  width: fit-content;
  margin: 0 0 12px;
  padding: 7px 10px;
  border: 2px solid #070411;
  border-radius: 8px;
  background: var(--mint);
  color: #062113;
  font-weight: 950;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 100%;
  font-family: Impact, Haettenschweiler, "Arial Black", sans-serif;
  font-size: clamp(2.25rem, 3.45vw, 3.55rem);
  line-height: 0.9;
  color: #fff;
  text-shadow: 6px 6px 0 #070411, 0 0 26px rgba(73, 231, 255, 0.66);
}

.start-hero p:not(.kicker) {
  max-width: 48rem;
  margin: 16px 0 0;
  font-size: clamp(1rem, 1.55vw, 1.18rem);
  font-weight: 800;
  line-height: 1.45;
  text-shadow: 0 3px 16px rgba(0, 0, 0, 0.65);
}

.control-panel,
.end-panel,
.leaderboard-panel {
  padding: clamp(18px, 3vw, 30px);
}

.control-panel {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: #fef7e8;
  font-weight: 900;
}

input,
select,
textarea {
  width: 100%;
  min-height: 48px;
  border: 2px solid #070411;
  border-radius: 8px;
  padding: 0 12px;
  background: #fff8e7;
  color: #180f2e;
  font-weight: 850;
  box-shadow: 4px 4px 0 #070411;
}

textarea {
  min-height: 88px;
  padding: 11px 12px;
  resize: vertical;
  line-height: 1.35;
}

.briefing {
  padding: 14px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.briefing p {
  margin: 7px 0 0;
  color: #efe6ff;
  line-height: 1.4;
}

.start-actions,
.action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  align-content: flex-start;
  gap: 10px;
}

.action-row {
  display: grid;
  grid-template-columns: repeat(3, max-content);
  justify-content: center;
  align-items: center;
  align-self: start;
  min-height: 62px;
  width: 100%;
}

.primary-button,
.secondary-button,
.icon-button {
  flex: 0 0 auto;
  min-height: 0;
  height: 42px !important;
  border: 3px solid #070411;
  border-radius: 8px;
  cursor: pointer;
  color: #10091f;
  font-weight: 950;
  text-decoration: none;
  box-shadow: 4px 4px 0 #070411;
  transition: transform 140ms ease, box-shadow 140ms ease, filter 140ms ease;
}

.primary-button {
  padding: 0 16px;
  background: linear-gradient(135deg, var(--yellow), var(--pink));
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  background: #fff8e7;
}

.icon-button {
  width: 42px;
  padding: 0;
  background: var(--danger);
}

.primary-button:hover,
.secondary-button:hover,
.icon-button:hover {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 #070411;
  filter: brightness(1.05);
}

.game-screen {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  height: 100vh;
}

.hud {
  display: grid;
  grid-template-columns: repeat(5, minmax(86px, 1fr)) minmax(190px, 1.3fr) minmax(92px, 0.72fr);
  gap: 10px;
}

.hud > div,
.hud-button {
  min-height: 66px;
  padding: 10px 12px;
  box-shadow: 4px 4px 0 #070411;
}

.hud-button {
  display: grid;
  place-items: center;
  color: #12091f;
  background: #fff8e7;
  cursor: pointer;
  font-weight: 950;
}

.hud span {
  display: block;
  color: #cfc2ef;
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.hud strong {
  display: block;
  margin-top: 4px;
  color: #fff;
  font-size: clamp(1.02rem, 1.8vw, 1.35rem);
}

.energy-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 10px;
  align-items: center;
}

.energy-card span,
.energy-shell {
  grid-column: 1 / -1;
}

.energy-shell {
  height: 16px;
  overflow: hidden;
  border: 2px solid #070411;
  border-radius: 999px;
  background: #2a183f;
}

.energy-fill {
  width: 60%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--danger), var(--yellow), var(--mint), var(--cyan));
  box-shadow: 0 0 18px rgba(103, 255, 173, 0.8);
  transition: width 360ms ease;
}

.game-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(560px, 1.28fr) minmax(420px, 0.72fr);
  gap: 14px;
}

.machine-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 3px solid #070411;
  border-radius: 8px;
  background: #170d2b;
  box-shadow: var(--shadow), 7px 7px 0 #070411;
}

.machine-stage::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: min(18%, 190px);
  height: min(28%, 220px);
  background: linear-gradient(135deg, rgba(48, 28, 38, 0.02), rgba(48, 28, 38, 0.72) 42%, rgba(30, 19, 36, 0.84));
  pointer-events: none;
}

.lab-art {
  width: 100%;
  height: 100%;
  min-height: 360px;
  object-fit: cover;
  object-position: center center;
  display: block;
  filter: saturate(1.08) contrast(1.02);
}

.machine-glow {
  position: absolute;
  inset: 12% 16% 18% 19%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(103, 255, 173, 0.28), rgba(73, 231, 255, 0.1) 36%, transparent 68%);
  opacity: 0.55;
  mix-blend-mode: screen;
  transition: opacity 220ms ease, transform 220ms ease;
  pointer-events: none;
}

.machine-stage.success .machine-glow {
  opacity: 1;
  transform: scale(1.08);
  animation: glowPulse 760ms ease;
}

.machine-stage.error {
  animation: machineCough 420ms ease;
}

.helper-bubble {
  position: absolute;
  left: 18px;
  bottom: 18px;
  width: min(360px, calc(100% - 36px));
  padding: 13px 15px;
  border: 3px solid #070411;
  border-radius: 8px;
  background: rgba(255, 248, 231, 0.94);
  color: #150d29;
  box-shadow: 5px 5px 0 #070411;
}

.helper-bubble strong,
.helper-bubble span {
  display: block;
}

.helper-bubble span {
  margin-top: 4px;
  font-weight: 800;
  line-height: 1.3;
}

.workbench {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(120px, auto) minmax(150px, 1fr) auto auto auto;
  gap: 10px;
  padding: 14px;
  background:
    linear-gradient(180deg, rgba(31, 18, 57, 0.95), rgba(20, 13, 39, 0.86)),
    url("assets/lab-ui-sprites.png") right bottom / 360px auto no-repeat;
}

.round-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #fef7e8;
  font-weight: 950;
}

.round-line span:first-child {
  color: var(--yellow);
}

.expert-prompt,
.feedback,
.marking-panel {
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.09);
  padding: 10px 12px;
  font-weight: 850;
  line-height: 1.35;
}

.expert-prompt {
  color: #ffe4f3;
}

.expert-workshop {
  display: grid;
  gap: 12px;
}

.wrong-sentence {
  min-height: 56px;
  padding: 14px;
  border: 3px solid #070411;
  border-radius: 8px;
  background: linear-gradient(135deg, #fff8e7, #ffe1f1);
  color: #160d2a;
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  font-weight: 950;
  box-shadow: 4px 4px 0 #070411;
}

.error-types {
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.error-types legend {
  padding: 0 6px;
  color: #fff8e7;
  font-weight: 950;
}

.error-type-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.error-choice {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border: 3px solid #070411;
  border-radius: 8px;
  background: #fff8e7;
  color: #160d2a;
  cursor: pointer;
  font-weight: 950;
  box-shadow: 3px 3px 0 #070411;
}

.error-choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.error-choice:has(input:checked) {
  background: linear-gradient(135deg, var(--cyan), var(--mint));
}

.expert-answer-label {
  color: #fff8e7;
}

.workbench.expert-mode {
  grid-template-rows: auto auto minmax(340px, 1fr) auto auto;
}

.zone-title {
  margin-bottom: 7px;
  color: #d4c8f2;
  font-size: 0.8rem;
  font-weight: 950;
  text-transform: uppercase;
}

.sentence-line,
.tile-bank {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 9px;
  min-height: 86px;
  padding: 10px;
  border: 3px dashed rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  background: rgba(4, 2, 12, 0.42);
}

.sentence-line {
  min-height: 126px;
}

.tile-bank {
  min-height: 150px;
  max-height: 32vh;
  overflow-y: auto;
}

.word-tile,
.sentence-token {
  min-height: 38px;
  border: 3px solid #070411;
  border-radius: 8px;
  padding: 7px 11px;
  background: linear-gradient(135deg, #fff8e7, #d8f9ff);
  color: #160d2a;
  cursor: pointer;
  font-weight: 950;
  box-shadow: 4px 4px 0 #070411;
  user-select: none;
}

.word-tile:focus,
.sentence-token:focus {
  outline: 3px solid var(--yellow);
  outline-offset: 3px;
}

.word-tile.dragging {
  opacity: 0.55;
}

.sentence-token {
  background: linear-gradient(135deg, var(--yellow), #fff8e7);
}

.sentence-token.marked-subject {
  background: linear-gradient(135deg, var(--cyan), #fff8e7);
}

.sentence-token.marked-verb {
  background: linear-gradient(135deg, var(--mint), #fff8e7);
}

.sentence-token.marked-object {
  background: linear-gradient(135deg, var(--pink), #fff8e7);
}

.feedback.good {
  border-color: rgba(103, 255, 173, 0.65);
  color: #dfffe9;
}

.feedback.bad {
  border-color: rgba(255, 106, 91, 0.7);
  color: #ffe4df;
}

.effect-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.burst,
.spark {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 12px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 18px var(--c);
  animation: pop 820ms ease forwards;
}

.spark {
  background: var(--danger);
  animation-name: fizz;
}

.end-screen {
  align-items: stretch;
}

.end-panel,
.leaderboard-panel {
  align-self: center;
}

.end-panel h2 {
  margin-bottom: 18px;
  font-size: clamp(2rem, 5vw, 4rem);
}

.end-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.stat-box {
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  font-weight: 900;
}

.stat-box span {
  display: block;
  margin-bottom: 4px;
  color: #d8cafd;
  font-size: 0.78rem;
  text-transform: uppercase;
}

.leaderboard-dialog {
  width: min(720px, calc(100% - 28px));
  border: 3px solid #070411;
  border-radius: 8px;
  padding: 0;
  background: var(--panel-strong);
  color: var(--ink);
  box-shadow: var(--shadow), 7px 7px 0 #070411;
}

.leaderboard-dialog::backdrop {
  background: rgba(5, 3, 14, 0.72);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border-bottom: 2px solid rgba(255, 255, 255, 0.18);
}

.leaderboard-list {
  display: grid;
  gap: 8px;
  padding: 16px;
}

.leader-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 76px 84px 72px 64px;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  font-weight: 850;
}

.leader-row:first-child {
  background: linear-gradient(135deg, rgba(255, 215, 90, 0.28), rgba(73, 231, 255, 0.16));
}

.leader-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@keyframes glowPulse {
  50% {
    filter: brightness(1.8);
  }
}

@keyframes machineCough {
  20% {
    transform: translateX(-5px) rotate(-0.5deg);
    filter: hue-rotate(20deg);
  }
  50% {
    transform: translateX(4px) rotate(0.4deg);
  }
}

@keyframes pop {
  to {
    transform: translate(var(--dx), var(--dy)) scale(0.15);
    opacity: 0;
  }
}

@keyframes fizz {
  to {
    transform: translate(var(--dx), var(--dy)) rotate(70deg);
    opacity: 0;
  }
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .screen,
  .game-screen {
    min-height: 100svh;
    height: auto;
  }

  .start-screen,
  .end-screen,
  .game-layout {
    grid-template-columns: 1fr;
  }

  .hud {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .machine-stage {
    min-height: 38vh;
  }

  .workbench {
    grid-template-rows: auto auto auto auto auto auto auto;
  }
}

@media (max-width: 820px) {
  .start-screen {
    grid-template-columns: 1fr;
  }

  .start-hero {
    min-height: 46vh;
  }
}

@media (max-width: 620px) {
  .screen {
    padding: 10px;
  }

  .start-screen {
    align-items: stretch;
  }

  .start-hero {
    min-height: 430px;
    padding: 18px;
  }

  h1 {
    font-size: clamp(2.8rem, 14vw, 4.4rem);
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .round-line,
  .start-actions,
  .action-row {
    flex-direction: column;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
    height: 42px !important;
  }

  .leader-row {
    grid-template-columns: 34px minmax(0, 1fr) 62px;
  }

  .leader-row span:nth-child(n + 4) {
    display: none;
  }
}
