:root {
  color-scheme: dark;
  --ink: #fffaf0;
  --muted: #cabfaa;
  --panel: rgba(14, 12, 10, 0.82);
  --strong: rgba(22, 17, 12, 0.94);
  --line: rgba(255, 245, 220, 0.18);
  --bamboo: #e8b95f;
  --jade: #61d394;
  --soy: #3d2117;
  --red: #ff5a5f;
  --blue: #57c7ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #090706;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

button,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

#game-canvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.26);
  pointer-events: auto;
}

.screen.is-visible {
  display: flex;
}

.start-panel,
.mini-panel {
  width: min(680px, 100%);
  padding: clamp(22px, 5vw, 42px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(28, 20, 12, 0.92), rgba(11, 9, 8, 0.78));
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(16px);
}

.mini-panel {
  max-width: 540px;
  text-align: center;
}

.back-link,
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  text-decoration: none;
  font-size: 30px;
  line-height: 1;
}

.eyebrow,
#level-kicker,
#end-kicker,
.hud-card p {
  margin: 14px 0 8px;
  color: var(--bamboo);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 0.96;
}

h1 {
  max-width: 720px;
  font-size: clamp(42px, 9vw, 96px);
}

h2 {
  font-size: clamp(34px, 7vw, 64px);
}

.preview-row {
  display: flex;
  gap: 10px;
  margin: 22px 0;
}

.preview-row span,
#order-chip {
  display: block;
  width: 38px;
  height: 38px;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 50%;
  background: var(--chip);
  box-shadow: inset 0 -8px 14px rgba(0, 0, 0, 0.16), 0 8px 20px rgba(0, 0, 0, 0.26);
}

.primary-button,
.ghost-button,
.ghost-link {
  display: inline-grid;
  place-items: center;
  min-width: 140px;
  min-height: 48px;
  padding: 12px 20px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: linear-gradient(135deg, #ffe08a, #61d394);
  color: #1d1208;
  font-weight: 900;
  text-decoration: none;
}

.ghost-button,
.ghost-link {
  width: 100%;
  margin-top: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
}

.mini-panel .primary-button {
  width: 100%;
  margin-top: 14px;
}

.mini-panel p {
  color: var(--muted);
  line-height: 1.5;
}

.hud {
  position: fixed;
  top: 14px;
  left: 14px;
  display: none;
  gap: 10px;
  align-items: flex-start;
  pointer-events: none;
}

.hud.is-visible {
  display: flex;
}

.hud-card {
  width: min(340px, calc(100vw - 28px));
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(12px);
}

.hud-card.compact {
  width: 150px;
}

.hud-card h2 {
  margin-bottom: 10px;
  font-size: 22px;
}

.order-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.order-row strong {
  min-width: 0;
  font-size: 18px;
}

.meter,
.steam-bar {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.14);
}

.meter span,
.steam-bar span {
  display: block;
  height: 100%;
  border-radius: 8px;
  transition: width 0.2s ease;
}

.meter span {
  width: 0;
  background: linear-gradient(90deg, var(--blue), var(--jade), var(--bamboo));
}

.steam-bar span {
  width: 100%;
  background: linear-gradient(90deg, #fff9df, #57c7ff);
}

.hud-line {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-weight: 900;
}

.toast {
  position: fixed;
  top: 18px;
  right: 18px;
  max-width: min(360px, calc(100vw - 36px));
  min-height: 44px;
  padding: 12px 14px;
  border: 1px solid rgba(232, 185, 95, 0.5);
  border-radius: 8px;
  background: rgba(32, 20, 8, 0.82);
  color: #ffe08a;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.icon-button {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 20;
  display: none;
  pointer-events: auto;
  font-size: 20px;
}

.icon-button.is-visible {
  display: grid;
}

.tablet-controls {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  display: none;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  pointer-events: auto;
  touch-action: none;
}

.move-pad {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(2, 64px);
  gap: 8px;
}

.move-pad button,
.action-pad button,
.look-pad {
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: rgba(22, 17, 12, 0.68);
  color: var(--ink);
  font-weight: 900;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(10px);
  touch-action: none;
}

.move-pad button,
.action-pad button {
  width: 64px;
  height: 64px;
  font-size: 24px;
}

.move-pad button:active,
.action-pad button:active,
.look-pad.is-active {
  border-color: rgba(255, 224, 138, 0.82);
  background: rgba(255, 224, 138, 0.18);
}

.move-pad [data-key="KeyW"] {
  grid-column: 2;
}

.move-pad [data-key="KeyA"] {
  grid-column: 1;
  grid-row: 2;
}

.move-pad [data-key="KeyD"] {
  grid-column: 3;
  grid-row: 2;
}

.move-pad [data-key="KeyS"] {
  grid-column: 2;
  grid-row: 2;
}

.look-pad {
  width: clamp(150px, 24vw, 240px);
  height: 112px;
  color: rgba(255, 250, 240, 0.74);
  font-size: 14px;
  text-transform: uppercase;
}

.action-pad {
  display: grid;
  grid-template-columns: 64px;
  gap: 8px;
}

.action-pad [data-key="ShiftLeft"] {
  color: #1d1208;
  background: linear-gradient(135deg, #ffe08a, #61d394);
}

@media (hover: none), (pointer: coarse), (max-width: 1180px) {
  .tablet-controls.is-visible {
    display: flex;
  }
}

@media (hover: none) and (orientation: portrait), (pointer: coarse) and (orientation: portrait), (max-width: 720px) {
  .look-pad {
    display: none;
  }
}

@media (max-width: 720px) {
  .screen {
    padding: 12px;
  }

  .start-panel,
  .mini-panel {
    padding: 18px;
  }

  .hud {
    top: 10px;
    left: 10px;
    right: 10px;
    flex-direction: column;
  }

  .hud-card,
  .hud-card.compact {
    width: min(300px, calc(100vw - 20px));
  }

  .toast {
    top: auto;
    right: 10px;
    bottom: 164px;
    left: 10px;
  }

  .tablet-controls {
    left: 10px;
    right: 10px;
    bottom: 10px;
    gap: 10px;
  }

  .move-pad {
    grid-template-columns: repeat(3, 56px);
    grid-template-rows: repeat(2, 56px);
    gap: 7px;
  }

  .move-pad button,
  .action-pad button {
    width: 56px;
    height: 56px;
  }

  .action-pad {
    grid-template-columns: 56px;
  }
}
