:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
}

body:not(.world-page) {
  color-scheme: dark;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 38%, rgba(35, 255, 112, 0.1), transparent 20rem),
    linear-gradient(145deg, #040a11, #0a1827);
  color: #f7fbff;
}

.shell {
  width: min(100%, 44rem);
  display: grid;
  justify-items: center;
  padding: 3rem 1.5rem;
  text-align: center;
}

.shell-login { gap: 2.5rem; transform: translateY(-3vh); }
.brand { display: grid; justify-items: center; gap: 1.25rem; }

.pixel {
  width: clamp(3rem, 8vw, 5.25rem);
  aspect-ratio: 1;
  background: #21ef62;
  box-shadow: 0 0 1.5rem rgba(33, 239, 98, 0.48), 0 0 5rem rgba(33, 239, 98, 0.18);
}

h1 {
  margin: 0;
  font-size: clamp(2.25rem, 8vw, 5.5rem);
  font-weight: 300;
  letter-spacing: 0.2em;
  line-height: 0.95;
}

.tagline {
  margin: 0;
  color: #33cfff;
  font-size: clamp(0.62rem, 1.6vw, 0.9rem);
  font-weight: 600;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

.login-card {
  width: min(100%, 23rem);
  border: 1px solid rgba(151, 198, 230, 0.18);
  border-radius: 1rem;
  padding: 1.5rem;
  background: rgba(8, 21, 34, 0.78);
  box-shadow: 0 1.5rem 5rem rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(18px);
  text-align: left;
}

.login-card form { display: grid; gap: 1rem; }
label { display: grid; gap: 0.45rem; }
label span { color: #aebdca; font-size: 0.76rem; font-weight: 600; }

input {
  width: 100%;
  border: 1px solid rgba(151, 198, 230, 0.2);
  border-radius: 0.65rem;
  outline: none;
  padding: 0.78rem 0.85rem;
  background: rgba(1, 8, 14, 0.62);
  color: #f7fbff;
  font: inherit;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input:focus {
  border-color: #33cfff;
  box-shadow: 0 0 0 3px rgba(51, 207, 255, 0.12);
}

.login-card button {
  border: 0;
  border-radius: 0.65rem;
  padding: 0.82rem 1rem;
  background: #21ef62;
  color: #04110a;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}

.login-card button:hover { background: #49f57b; }

.error {
  margin: 0 0 1rem;
  border: 1px solid rgba(255, 103, 115, 0.25);
  border-radius: 0.6rem;
  padding: 0.65rem 0.75rem;
  background: rgba(255, 71, 87, 0.08);
  color: #ff9aa3;
  font-size: 0.78rem;
}

.world-page {
  overflow: hidden;
  background: #f7f8f4;
  color: #15231c;
}

.world-app {
  width: 100vw;
  height: 100dvh;
  display: grid;
  grid-template-rows: 62px 1fr;
}

.world-header {
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(10rem, 1fr) auto minmax(10rem, 1fr);
  align-items: center;
  gap: 1rem;
  border-bottom: 1px solid #dfe6df;
  padding: 0 1.1rem;
  background: rgba(255, 255, 252, 0.94);
  box-shadow: 0 1px 12px rgba(27, 47, 37, 0.05);
  backdrop-filter: blur(14px);
}

.world-wordmark {
  display: flex;
  align-items: center;
  gap: 0.72rem;
  min-width: 0;
  color: #16231c;
  font-size: 0.84rem;
  font-weight: 650;
  letter-spacing: 0.25em;
  white-space: nowrap;
}

.world-mark {
  width: 16px;
  aspect-ratio: 1;
  flex: none;
  background: #20e765;
  box-shadow: 0 0 12px rgba(32, 231, 101, 0.48);
}

.coordinate-control {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  min-height: 38px;
  border: 1px solid #dce5de;
  border-radius: 10px;
  padding: 0.35rem 0.55rem 0.35rem 0.78rem;
  background: #f9faf7;
  color: #4d5a53;
  font: inherit;
  cursor: pointer;
}

.coordinate-control:hover { border-color: #b9c9be; background: #fff; }
.coordinate-control small { color: #8a968f; font-size: 0.68rem; }
.coordinate-control strong { color: #213229; font-size: 0.78rem; font-variant-numeric: tabular-nums; }

.origin-chip {
  border-radius: 6px;
  padding: 0.3rem 0.45rem;
  background: #dff8e6;
  color: #148b43;
  font-size: 0.7rem;
  font-weight: 750;
}

.coordinate-center {
  padding-right: 0.25rem;
  color: #536159;
  font-size: 0.72rem;
  font-weight: 650;
}

.world-header-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.agent-state {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: #708078;
  font-size: 0.72rem;
  font-weight: 650;
  white-space: nowrap;
}

.agent-state-dot {
  width: 7px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #a6b0aa;
}

.user-chip {
  display: grid;
  place-items: center;
  width: 31px;
  aspect-ratio: 1;
  border-radius: 9px;
  background: #20e765;
  color: #073417;
  font-size: 0.68rem;
  font-weight: 800;
}

.logout-button {
  border: 1px solid #dce5de;
  border-radius: 9px;
  padding: 0.52rem 0.68rem;
  background: #fff;
  color: #536159;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
}

.logout-button:hover { border-color: #b9c9be; color: #1e2d25; }

.world-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #fffefa;
  isolation: isolate;
}

#worldCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#worldCanvas.dragging { cursor: grabbing; }
#worldCanvas.tap-mode { cursor: crosshair; }

.tool-rail,
.zoom-controls,
.world-status,
.world-hint {
  position: absolute;
  z-index: 4;
}

.tool-rail {
  top: 16px;
  left: 16px;
  width: 54px;
  display: grid;
  gap: 4px;
  border: 1px solid rgba(198, 209, 201, 0.9);
  border-radius: 15px;
  padding: 6px;
  background: rgba(255, 255, 252, 0.92);
  box-shadow: 0 12px 32px rgba(39, 60, 49, 0.11);
  backdrop-filter: blur(12px);
}

.tool-button {
  min-height: 46px;
  display: grid;
  place-items: center;
  gap: 1px;
  border: 0;
  border-radius: 10px;
  padding: 4px 2px;
  background: transparent;
  color: #66736c;
  font: inherit;
  font-size: 0.52rem;
  font-weight: 700;
  cursor: pointer;
}

.tool-button:hover { background: #f1f5f0; color: #1d3025; }
.tool-button.active { background: #e3f9e9; color: #0a7d38; box-shadow: inset 0 0 0 1px #b9edc7; }
.tool-symbol { font-size: 1.25rem; font-weight: 400; line-height: 1; }
.tool-divider { height: 1px; margin: 3px 5px; background: #e2e8e3; }

.zoom-controls {
  left: 16px;
  bottom: 18px;
  display: grid;
  overflow: hidden;
  border: 1px solid rgba(198, 209, 201, 0.9);
  border-radius: 12px;
  background: rgba(255, 255, 252, 0.94);
  box-shadow: 0 10px 25px rgba(39, 60, 49, 0.1);
}

.zoom-controls button {
  width: 42px;
  height: 38px;
  border: 0;
  border-bottom: 1px solid #e4e9e5;
  background: transparent;
  color: #3f5047;
  font: inherit;
  font-size: 1.1rem;
  cursor: pointer;
}

.zoom-controls button:last-child { border-bottom: 0; }
.zoom-controls button:hover { background: #edf5ef; color: #0d803c; }

.world-hint {
  left: 50%;
  bottom: 82px;
  transform: translateX(-50%);
  border: 1px solid rgba(210, 220, 212, 0.9);
  border-radius: 999px;
  padding: 0.5rem 0.78rem;
  background: rgba(255, 255, 252, 0.92);
  box-shadow: 0 8px 24px rgba(38, 56, 47, 0.08);
  color: #718078;
  font-size: 0.68rem;
  font-weight: 650;
  white-space: nowrap;
  transition: opacity 300ms ease, transform 300ms ease;
}

.world-hint.hidden { opacity: 0; transform: translate(-50%, 8px); pointer-events: none; }

.world-status {
  right: 16px;
  bottom: 18px;
  display: grid;
  grid-template-columns: repeat(4, minmax(78px, auto));
  overflow: hidden;
  border: 1px solid rgba(198, 209, 201, 0.9);
  border-radius: 14px;
  background: rgba(255, 255, 252, 0.94);
  box-shadow: 0 12px 32px rgba(39, 60, 49, 0.11);
  backdrop-filter: blur(12px);
}

.world-stat {
  min-width: 92px;
  display: grid;
  gap: 0.18rem;
  border-right: 1px solid #e4e9e5;
  padding: 0.68rem 0.85rem;
}

.world-stat:last-child { border-right: 0; }
.world-stat span { color: #849189; font-size: 0.55rem; font-weight: 750; letter-spacing: 0.12em; text-transform: uppercase; }
.world-stat strong { color: #24352c; font-size: 0.72rem; font-weight: 750; white-space: nowrap; font-variant-numeric: tabular-nums; }
.move-stat i { display: inline-block; width: 7px; aspect-ratio: 1; margin-right: 0.25rem; background: #20e765; vertical-align: -1px; }

@media (max-width: 760px) {
  .world-header { grid-template-columns: 1fr auto; padding: 0 0.75rem; }
  .coordinate-control { position: absolute; left: 50%; transform: translateX(-50%); }
  .agent-state-copy, .coordinate-center { display: none; }
  .world-wordmark { font-size: 0.7rem; letter-spacing: 0.18em; }
  .world-status { left: 82px; right: 10px; bottom: 10px; grid-template-columns: repeat(3, 1fr); }
  .world-stat { min-width: 0; padding: 0.58rem 0.62rem; }
  .move-stat { display: none; }
  .zoom-controls { left: 10px; bottom: 10px; }
  .tool-rail { left: 10px; top: 10px; }
  .world-hint { bottom: 76px; }
}

@media (max-width: 480px) {
  .world-app { grid-template-rows: 56px 1fr; }
  .world-header-actions form, .agent-state { display: none; }
  .coordinate-control { gap: 0.4rem; padding-left: 0.5rem; }
  .tool-rail { width: 49px; }
  .tool-button { min-height: 42px; }
}

@media (max-height: 760px) {
  .shell-login { gap: 1.5rem; transform: none; }
  .brand { gap: 0.8rem; }
  .pixel { width: 3rem; }
  .tool-button { min-height: 39px; }
  .tool-rail { gap: 2px; }
}
