:root {
  --paper: #f8f9fa;
  --ink: #202122;
  --muted: #54595d;
  --rule: #a2a9b1;
  --link: #0645ad;
  --visited: #0b0080;
  --hud: rgba(255, 255, 255, 0.86);
  --accent: #d12c2c;
  --success: #14866d;
  --shadow: rgba(32, 33, 34, 0.18);
  --surfer-size: 19.2px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.game-shell {
  position: fixed;
  inset: 0;
  height: 100dvh;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(162, 169, 177, 0.22) 1px, transparent 1px),
    linear-gradient(180deg, rgba(162, 169, 177, 0.12) 1px, transparent 1px),
    #eaecf0;
  background-size: 32px 32px;
  touch-action: none;
  user-select: none;
}

.viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  cursor: crosshair;
}

.world {
  position: absolute;
  top: 0;
  left: 0;
  width: 760px;
  min-height: 3200px;
  transform-origin: 0 0;
  will-change: transform;
}

.wiki-article {
  position: relative;
  width: 760px;
  min-height: 3200px;
  padding: 54px 66px 120px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(162, 169, 177, 0.35), 0 30px 80px var(--shadow);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  line-height: 1.55;
}

.wiki-article h1,
.wiki-article h2,
.wiki-article h3 {
  margin: 0;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
}

.wiki-article h1 {
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
  font-size: 34px;
  line-height: 1.2;
}

.wiki-article h2 {
  clear: both;
  margin-top: 30px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--rule);
  font-size: 24px;
}

.wiki-article h3 {
  margin-top: 22px;
  font-size: 19px;
  font-weight: 700;
}

.wiki-article p,
.wiki-article li {
  margin: 12px 0;
}

.wiki-article ul {
  margin: 8px 0 18px 22px;
  padding: 0;
}

.wiki-article a {
  color: var(--link);
  text-decoration: none;
}

.wiki-article a:hover {
  text-decoration: underline;
}

.wiki-article .collected {
  color: var(--visited);
  background: rgba(20, 134, 109, 0.14);
  border-radius: 2px;
}

.wiki-subtitle {
  margin: 0 0 18px;
  color: var(--muted);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
}

.infobox {
  float: right;
  width: 218px;
  margin: 2px 0 18px 22px;
  border: 1px solid var(--rule);
  background: #f8f9fa;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 12px;
  line-height: 1.4;
}

.infobox-title {
  padding: 8px 10px;
  background: #cedff2;
  color: #202122;
  font-weight: 700;
  text-align: center;
}

.infobox-row {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 8px;
  padding: 7px 9px;
  border-top: 1px solid rgba(162, 169, 177, 0.55);
}

.infobox-row b {
  font-weight: 700;
}

.word {
  display: inline-block;
  border-radius: 2px;
}

.link-word {
  position: relative;
}

.link-word::after {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 1px;
  height: 1px;
  background: currentColor;
  content: "";
  opacity: 0.7;
}

.surfer {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--surfer-size);
  height: var(--surfer-size);
  transform-origin: 50% 50%;
  will-change: transform;
  z-index: 10;
  --lift: 0px;
  --shadow-scale: 1;
  --shadow-opacity: 0.55;
}

.surfer-lift {
  position: absolute;
  inset: 0;
  transform: translateY(calc(-1 * var(--lift)));
  transform-origin: 50% 70%;
  will-change: transform;
}

.surfer img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.23));
}

.surfer-shadow {
  position: absolute;
  left: 20%;
  top: 58%;
  width: 60%;
  height: 25%;
  border-radius: 999px;
  background: rgba(32, 33, 34, 0.25);
  transform: scale(var(--shadow-scale));
  transform-origin: 50% 50%;
  opacity: var(--shadow-opacity);
}

.steer-dot {
  position: fixed;
  left: 0;
  top: 0;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border: 2px solid rgba(6, 69, 173, 0.9);
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
  transform: translate3d(-100px, -100px, 0) scale(0.84);
  transition: opacity 120ms ease;
  z-index: 12;
}

.steer-dot.is-visible {
  opacity: 0.76;
}

.steer-dot::after {
  position: absolute;
  inset: 9px;
  border-radius: inherit;
  background: rgba(6, 69, 173, 0.35);
  content: "";
}

.hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  display: flex;
  align-items: stretch;
  gap: 8px;
  max-width: calc(100vw - 72px);
  pointer-events: none;
  z-index: 20;
}

.hud-item {
  min-width: 64px;
  padding: 7px 9px;
  border: 1px solid rgba(162, 169, 177, 0.5);
  border-radius: 7px;
  background: var(--hud);
  box-shadow: 0 7px 24px rgba(32, 33, 34, 0.12);
  backdrop-filter: blur(12px);
}

.hud-label {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hud strong {
  display: block;
  margin-top: 1px;
  font-size: 18px;
  line-height: 1.1;
}

.hud-stability {
  width: 104px;
}

.hud-target {
  min-width: 94px;
}

.hud-target strong {
  max-width: 112px;
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meter {
  display: block;
  width: 100%;
  height: 8px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #eaecf0;
}

.meter span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #d12c2c, #d9a441 42%, #14866d);
  transform-origin: 0 50%;
}

.icon-button {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: 4px 4px;
  gap: 4px;
  place-content: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(162, 169, 177, 0.55);
  border-radius: 7px;
  background: var(--hud);
  box-shadow: 0 7px 24px rgba(32, 33, 34, 0.12);
  backdrop-filter: blur(12px);
  cursor: pointer;
  z-index: 21;
}

.icon-button span {
  width: 4px;
  height: 16px;
  border-radius: 2px;
  background: var(--ink);
}

.icon-button.is-paused {
  grid-template-columns: 0;
  gap: 0;
}

.icon-button.is-paused span:first-child {
  width: 0;
  height: 0;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-left: 15px solid var(--ink);
  border-radius: 0;
  background: transparent;
}

.icon-button.is-paused span:last-child {
  display: none;
}

.action-buttons {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
  z-index: 23;
}

.action-button {
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid rgba(162, 169, 177, 0.58);
  border-radius: 7px;
  background: var(--hud);
  box-shadow: 0 8px 24px rgba(32, 33, 34, 0.14);
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  backdrop-filter: blur(12px);
  cursor: pointer;
}

.action-button:active {
  transform: translateY(1px);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 52px);
  max-width: min(340px, calc(100vw - 32px));
  padding: 9px 12px;
  border: 1px solid rgba(162, 169, 177, 0.5);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 30px rgba(32, 33, 34, 0.14);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate3d(-50%, 14px, 0);
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 22;
}

.toast.is-visible {
  opacity: 1;
  transform: translate3d(-50%, 0, 0);
}

.screen-pulse {
  position: fixed;
  inset: 0;
  background: rgba(209, 44, 44, 0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 240ms ease;
  z-index: 18;
}

.screen-pulse.is-active {
  opacity: 1;
  transition-duration: 40ms;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(248, 249, 250, 0.74);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  z-index: 40;
  backdrop-filter: blur(10px);
}

.overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.overlay-panel {
  width: min(360px, 100%);
  padding: 26px 24px 24px;
  border: 1px solid rgba(162, 169, 177, 0.65);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 24px 70px rgba(32, 33, 34, 0.16);
  text-align: center;
}

.overlay-panel h1,
.overlay-panel h2 {
  margin: 0 0 20px;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(35px, 11vw, 52px);
  font-weight: 400;
  line-height: 1;
}

.overlay-panel h2 {
  font-size: clamp(32px, 10vw, 44px);
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.finish-stats {
  min-height: 20px;
  margin: -8px 0 18px;
  color: var(--muted);
  font-size: 14px;
}

.primary-button {
  min-width: 148px;
  min-height: 46px;
  padding: 11px 18px;
  border: 1px solid #36c;
  border-radius: 7px;
  background: #36c;
  color: #fff;
  box-shadow: 0 10px 24px rgba(51, 102, 204, 0.23);
  font-weight: 800;
  cursor: pointer;
}

.primary-button:active {
  transform: translateY(1px);
}

@media (max-width: 700px) {
  .world {
    width: 700px;
  }

  .wiki-article {
    width: 700px;
    padding: 48px 54px 110px;
    font-size: 15px;
  }

  .infobox {
    width: 190px;
    margin-left: 16px;
  }

  .hud {
    gap: 6px;
  }

  .hud-item {
    min-width: 58px;
    padding: 6px 8px;
  }

  .hud-stability {
    width: 88px;
  }

  .hud-target {
    min-width: 82px;
  }
}

@media (max-width: 430px) {
  .hud-label {
    font-size: 9px;
  }

  .hud strong {
    font-size: 16px;
  }

  .hud-target strong {
    max-width: 82px;
    font-size: 13px;
  }

  .hud-stability {
    display: none;
  }

  .action-buttons {
    right: 10px;
    bottom: max(12px, env(safe-area-inset-bottom));
    gap: 6px;
  }

  .action-button {
    min-height: 38px;
    padding: 8px 10px;
    font-size: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .world,
  .surfer,
  .surfer-lift,
  .toast,
  .overlay,
  .screen-pulse {
    transition: none;
  }
}
