:root {
  color-scheme: light;
  --ink: #173047;
  --muted: #607184;
  --line: rgba(23, 48, 71, 0.16);
  --panel: rgba(255, 255, 255, 0.9);
  --panel-strong: #ffffff;
  --sky: #9ce3ff;
  --sea: #26b8c7;
  --grass: #73ce79;
  --coral: #ff7b7b;
  --gold: #ffd35b;
  --rose: #ff9ec2;
  --mint: #8ff0bf;
  --shadow: 0 18px 50px rgba(29, 72, 95, 0.18);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 18%, rgba(255, 211, 91, 0.32), transparent 24%),
    radial-gradient(circle at 82% 22%, rgba(255, 123, 123, 0.26), transparent 28%),
    linear-gradient(160deg, #e7fbff 0%, #f9fff2 42%, #fff4f8 100%);
}

button {
  font: inherit;
}

.game-shell {
  min-height: 100vh;
  padding: 14px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
}

.topbar {
  min-height: 74px;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.eyebrow {
  margin: 0 0 2px;
  color: #0c7f91;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 2.2vw, 2rem);
  line-height: 1.1;
}

h2 {
  margin-bottom: 8px;
  font-size: 0.98rem;
}

h3 {
  margin-bottom: 6px;
  font-size: 0.94rem;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.status-strip span,
.pill,
.cooldown {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  color: #214052;
  background: #f3fcff;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 800;
}

.top-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.icon-button,
.menu-button,
.primary-action,
.social-grid button,
.action-pad button,
.pad {
  border: 1px solid rgba(23, 48, 71, 0.16);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

.icon-button:hover,
.menu-button:hover,
.primary-action:hover,
.social-grid button:hover,
.action-pad button:hover,
.pad:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(29, 72, 95, 0.12);
  border-color: rgba(23, 48, 71, 0.26);
}

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  font-size: 1.05rem;
  font-weight: 900;
}

.play-area {
  min-height: 0;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 250px;
  gap: 12px;
}

.panel {
  min-height: 0;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  overflow: auto;
}

.primary-action,
.menu-button {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 900;
}

.primary-action {
  background: linear-gradient(135deg, var(--coral), var(--gold));
  color: #441c10;
}

.menu-button {
  background: #ffffff;
}

.button-icon {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  font-weight: 900;
}

.mini-section {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.mini-section:first-of-type {
  border-top: 0;
}

.control-list {
  margin: 0;
  display: grid;
  gap: 8px;
}

.control-list div {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 8px;
  align-items: start;
}

.control-list dt {
  color: #0c7f91;
  font-size: 0.78rem;
  font-weight: 900;
}

.control-list dd {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.cooldown {
  width: 100%;
  margin: 8px 0 0;
  justify-content: flex-start;
  background: #fff8db;
}

.stage-wrap {
  position: relative;
  min-width: 0;
  min-height: 560px;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  background: #69d3ec;
  box-shadow: 0 18px 50px rgba(29, 72, 95, 0.14);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 560px;
  cursor: crosshair;
  touch-action: none;
}

.crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.crosshair::before,
.crosshair::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 1px 4px rgba(23, 48, 71, 0.28);
}

.crosshair::before {
  left: 8px;
  top: 1px;
  width: 2px;
  height: 16px;
}

.crosshair::after {
  left: 1px;
  top: 8px;
  width: 16px;
  height: 2px;
}

.banner {
  position: absolute;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  max-width: min(760px, calc(100% - 28px));
  padding: 12px 16px;
  color: #1a2733;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 38px rgba(29, 72, 95, 0.18);
  font-weight: 900;
  text-align: center;
}

.hidden {
  display: none;
}

.touch-controls {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.dpad,
.action-pad {
  pointer-events: auto;
}

.dpad {
  width: 132px;
  height: 132px;
  display: grid;
  grid-template-areas:
    ". up ."
    "left . right"
    ". down .";
  gap: 4px;
}

.pad,
.action-pad button {
  min-width: 42px;
  min-height: 42px;
  color: #163342;
  background: rgba(255, 255, 255, 0.86);
  font-weight: 900;
  touch-action: none;
}

.pad.up {
  grid-area: up;
}

.pad.left {
  grid-area: left;
}

.pad.right {
  grid-area: right;
}

.pad.down {
  grid-area: down;
}

.action-pad {
  display: grid;
  grid-template-columns: repeat(2, 48px);
  gap: 7px;
  align-content: end;
}

.social-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.social-grid button {
  min-height: 36px;
  background: #f5fbff;
  font-size: 0.84rem;
  font-weight: 800;
}

.rules-list {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.65;
}

.message-log {
  display: grid;
  gap: 7px;
  max-height: 180px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 0.82rem;
}

.message-log li {
  padding: 7px 8px;
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(23, 48, 71, 0.1);
  border-radius: 8px;
}

.dialog-panel {
  width: min(760px, calc(100vw - 28px));
  padding: 0;
  color: var(--ink);
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(16, 48, 70, 0.24);
}

.dialog-panel::backdrop {
  background: rgba(19, 48, 66, 0.32);
  backdrop-filter: blur(3px);
}

.dialog-panel form {
  padding: 16px;
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

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

.skin-card {
  min-height: 152px;
  padding: 10px;
  display: grid;
  align-content: end;
  gap: 8px;
  text-align: left;
  background: #f8fdff;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.skin-preview-pair {
  height: 82px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.skin-preview {
  min-width: 0;
  height: 82px;
  border-radius: 8px;
  border: 1px solid rgba(23, 48, 71, 0.12);
  background-color: #edf9ff;
  background-repeat: no-repeat;
  background-size: 300% 200%;
}

.skin-card strong {
  font-size: 0.9rem;
}

.skin-card span {
  color: var(--muted);
  font-size: 0.78rem;
}

.skin-card.active {
  outline: 3px solid rgba(255, 123, 123, 0.38);
  background: #fff9fb;
}

.dialog-note,
.tutorial-grid p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

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

.tutorial-grid section {
  padding: 12px;
  background: #f8fdff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  padding: 0;
  margin: 14px 0 0;
}

.dialog-actions .primary-action {
  width: auto;
  min-width: 136px;
  margin: 0;
  padding: 0 14px;
}

@media (max-width: 1080px) {
  .play-area {
    grid-template-columns: 210px minmax(0, 1fr);
  }

  .right-panel {
    display: none;
  }
}

@media (max-width: 760px) {
  .game-shell {
    padding: 8px;
  }

  .topbar {
    grid-template-columns: 1fr auto;
  }

  .status-strip {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .play-area {
    grid-template-columns: 1fr;
  }

  .left-panel {
    order: 2;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .left-panel .mini-section {
    display: none;
  }

  .primary-action,
  .menu-button {
    min-height: 42px;
    margin: 0;
    font-size: 0.86rem;
  }

  .stage-wrap,
  #gameCanvas {
    min-height: 520px;
  }

  .skin-grid,
  .tutorial-grid {
    grid-template-columns: 1fr;
  }
}

.facility-action {
  position: absolute;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%);
  padding: 14px 32px;
  color: #fff;
  background: linear-gradient(135deg, #ff8f5e, #ff6b3d);
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 28px;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 2px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(255, 107, 61, 0.4);
  z-index: 10;
  pointer-events: auto;
  transition: transform 0.15s, box-shadow 0.15s;
}

.facility-action:hover {
  transform: translateX(-50%) scale(1.06);
  box-shadow: 0 6px 24px rgba(255, 107, 61, 0.55);
}

.facility-action:active {
  transform: translateX(-50%) scale(0.97);
}

#chatInput {
  width: 100%;
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
}

.rankings-overlay {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, 80%);
  max-height: 55%;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 14px;
  padding: 14px 18px;
  font-size: 13px;
  color: #173047;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  z-index: 15;
  pointer-events: auto;
}

.rankings-overlay.hidden {
  display: none;
}

.rankings-overlay h3 {
  text-align: center;
  font-size: 16px;
  font-weight: 800;
  margin: 0 0 10px 0;
  color: #2a1848;
}

.rankings-overlay ol {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: rank;
}

.rankings-overlay li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 13px;
  counter-increment: rank;
}

.rankings-overlay li:nth-child(1) {
  background: rgba(255, 211, 91, 0.25);
  font-weight: 700;
}

.rankings-overlay li:nth-child(2) {
  background: rgba(192, 192, 192, 0.2);
  font-weight: 600;
}

.rankings-overlay li:nth-child(3) {
  background: rgba(205, 127, 50, 0.2);
  font-weight: 600;
}

.rankings-overlay li.eliminated {
  opacity: 0.5;
}

.rankings-overlay .rank-num {
  min-width: 28px;
  font-weight: 800;
  text-align: center;
}

.rankings-overlay .rank-name {
  flex: 1;
}

.rankings-overlay .rank-time {
  font-variant-numeric: tabular-nums;
  color: #5a6e82;
}

/* Coaster speed panel */
.coaster-speed-panel {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.88);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  z-index: 12;
}

.coaster-speed-label {
  font-weight: 900;
  font-size: 13px;
  text-align: center;
  color: #173047;
}

.coaster-speed-btn {
  width: 52px;
  height: 36px;
  border: 2px solid #d0d0d0;
  border-radius: 8px;
  background: #fff;
  font-weight: 900;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.12s;
}

.coaster-speed-btn.active {
  background: linear-gradient(135deg, #ff8f5e, #ff6b3d);
  color: #fff;
  border-color: #ff6b3d;
}

.coaster-speed-btn:hover {
  transform: scale(1.05);
}

/* Coaster horn button */
.coaster-horn-btn {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid #ffd35b;
  background: rgba(255, 255, 255, 0.9);
  font-size: 24px;
  cursor: pointer;
  z-index: 12;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.coaster-horn-btn:active {
  transform: translateY(-50%) scale(0.9);
}

/* Coaster car selection grid */
.coaster-car-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.coaster-car-btn {
  height: 44px;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 10px;
  font-weight: 900;
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

.coaster-car-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
