:root {
  color-scheme: light;
  --ink: #18202c;
  --muted: #667083;
  --paper: #f5f2ea;
  --panel: #ffffff;
  --line: #d9d4c8;
  --green: #2f8f6b;
  --green-dark: #1f6f58;
  --red: #d24f45;
  --yellow: #f2b84b;
  --blue: #4f74b8;
  --sky: #cfe8f2;
  --key: #fbfaf7;
  --shadow: 0 16px 42px rgba(25, 32, 44, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(207, 232, 242, 0.9), rgba(245, 242, 234, 0.98) 54%),
    var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

.profile-panel,
.play-stage {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(217, 212, 200, 0.9);
  box-shadow: var(--shadow);
}

.profile-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  border-radius: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--yellow);
  font-weight: 900;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.45rem;
  line-height: 1.1;
}

h2 {
  font-size: 1.65rem;
  line-height: 1.1;
}

.brand p,
.eyebrow,
label,
.target-strip span,
.stat-grid span,
.range-labels {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

.profile-form {
  display: grid;
  gap: 8px;
}

.profile-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

input[type="text"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffdf9;
  color: var(--ink);
  padding: 11px 12px;
  outline: 0;
}

select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffdf9;
  color: var(--ink);
  padding: 0 12px;
  outline: 0;
}

input[type="text"]:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 143, 107, 0.17);
}

select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 143, 107, 0.17);
}

input.shake {
  border-color: var(--red);
  animation: shake 120ms linear;
}

.primary-button,
.icon-button,
.profile-chip,
.game-tab {
  min-height: 42px;
  border-radius: 7px;
  font-weight: 850;
}

.primary-button {
  background: var(--green);
  color: white;
  padding: 0 16px;
}

.primary-button:hover {
  background: var(--green-dark);
}

.icon-button {
  width: 46px;
  background: #ece7dd;
  color: var(--ink);
}

.profile-list,
.game-tabs {
  display: grid;
  gap: 8px;
}

.profile-chip,
.game-tab {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: #f3efe6;
  color: var(--ink);
  text-align: left;
}

.profile-chip.active,
.game-tab.active {
  background: #dff1e9;
  outline: 2px solid rgba(47, 143, 107, 0.38);
}

.profile-chip small,
.game-tab small {
  color: var(--muted);
  font-weight: 700;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.stat-grid div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffdf9;
  padding: 12px;
}

.stat-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 1.4rem;
}

.control-group {
  display: grid;
  gap: 8px;
}

input[type="range"] {
  min-height: 34px;
  accent-color: var(--green);
}

.range-labels {
  display: flex;
  justify-content: space-between;
}

.play-stage {
  display: grid;
  grid-template-rows: auto minmax(330px, 1fr) auto auto;
  gap: 14px;
  min-width: 0;
  padding: 18px;
  border-radius: 8px;
}

.stage-toolbar,
.typing-dock {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.difficulty-meter {
  display: grid;
  gap: 5px;
  width: min(260px, 32vw);
  min-width: 190px;
  margin-left: auto;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffdf9;
}

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

.meter-top span,
.difficulty-meter small {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.meter-top strong {
  font-size: 0.95rem;
}

.meter-track {
  overflow: hidden;
  height: 9px;
  border-radius: 999px;
  background: #ece7dd;
}

.meter-track div {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--yellow));
  transition: width 180ms ease;
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  min-height: 330px;
  border: 2px solid #243448;
  border-radius: 8px;
  background: #8ccfe1;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(24, 32, 44, 0.22);
  color: white;
  font-size: clamp(4rem, 16vw, 9rem);
  font-weight: 950;
  text-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
}

.typing-dock {
  flex-wrap: wrap;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf9;
}

.target-strip {
  display: grid;
  gap: 2px;
}

.target-strip strong {
  min-width: 12ch;
  font-size: 1.45rem;
}

.target-strip strong span {
  color: var(--muted);
}

.target-strip strong .battle-choice {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-right: 10px;
  color: var(--muted);
  white-space: nowrap;
}

.target-strip strong .battle-choice b {
  color: var(--ink);
}

#typingInput {
  flex: 1 1 260px;
  min-height: 46px;
  font-size: 1.2rem;
  font-weight: 800;
}

.keyboard-panel {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f4eb;
  padding: 12px;
}

.hands {
  display: flex;
  justify-content: space-between;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
  pointer-events: none;
}

.hand {
  display: flex;
  gap: 5px;
  align-items: end;
}

.hand span {
  display: block;
  width: 18px;
  height: 36px;
  border-radius: 9px 9px 6px 6px;
  background: #ddb18f;
  border: 1px solid rgba(112, 78, 55, 0.2);
}

.hand span:nth-child(2),
.hand span:nth-child(4) {
  height: 44px;
}

.hand span:nth-child(3) {
  height: 50px;
}

.keyboard {
  display: grid;
  gap: 6px;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}

.key-row {
  display: grid;
  grid-template-columns: repeat(10, minmax(24px, 1fr));
  gap: 6px;
}

.key-row:nth-child(2) {
  padding-inline: 5%;
}

.key-row:nth-child(3) {
  padding-inline: 10%;
}

.key {
  display: grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid #c9c2b5;
  border-bottom-width: 3px;
  border-radius: 7px;
  background: var(--key);
  font-weight: 900;
}

.key.home {
  background: #dff1e9;
  border-color: #8ecab2;
}

.key.next {
  background: #fce9bd;
  border-color: #e6b74f;
}

.key.active {
  background: var(--green);
  border-color: var(--green-dark);
  color: white;
  transform: translateY(2px);
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .profile-panel {
    order: 2;
  }

  .play-stage {
    order: 1;
    grid-template-rows: auto 48vh auto auto;
  }
}

@media (max-width: 540px) {
  .stage-toolbar,
  .typing-dock {
    align-items: stretch;
    flex-direction: column;
  }

  .difficulty-meter {
    width: 100%;
    margin-left: 0;
  }

  .toolbar-actions,
  .profile-row {
    display: grid;
    grid-template-columns: 1fr auto;
    width: 100%;
  }

  .primary-button {
    min-width: 84px;
  }

  .key {
    min-height: 34px;
    font-size: 0.85rem;
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }

  33% {
    transform: translateX(-4px);
  }

  66% {
    transform: translateX(4px);
  }
}
