:root {
  --bg: #071018;
  --panel: rgba(12, 22, 34, 0.76);
  --line: rgba(139, 244, 255, 0.22);
  --text: #eef8ff;
  --muted: rgba(238, 248, 255, 0.68);
  --cyan: #6ee7ff;
  --pink: #ff5db8;
  --green: #7dff88;
  --amber: #ffd36e;
  --danger: #ff6b6b;
  --body-bg:
    radial-gradient(circle at 14% 18%, rgba(110, 231, 255, 0.2), transparent 28%),
    radial-gradient(circle at 82% 22%, rgba(255, 93, 184, 0.18), transparent 28%),
    linear-gradient(180deg, #101725 0%, #071018 56%, #03060a 100%);
  --grid-line: rgba(110, 231, 255, 0.05);
  --topbar-bg: linear-gradient(180deg, rgba(15, 27, 43, 0.88), rgba(7, 16, 24, 0.74));
  --surface-bg: rgba(3, 8, 14, 0.36);
  --control-bg: rgba(255, 255, 255, 0.05);
  --control-border: rgba(255, 255, 255, 0.1);
  --control-active: rgba(110, 231, 255, 0.1);
  --hud-bg: rgba(4, 10, 18, 0.68);
  --canvas-sea-top: rgba(110, 231, 255, 0.08);
  --canvas-sea-bottom: rgba(40, 120, 150, 0.3);
  --canvas-wave: rgba(110, 231, 255, 0.18);
  --ship-body: rgba(255, 211, 110, 0.92);
  --ship-sail: rgba(110, 231, 255, 0.82);
  --cannon-main: rgba(255, 93, 184, 0.9);
  --cannon-base: rgba(110, 231, 255, 0.88);
  --ink: #071018;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--body-bg);
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  transition: background 240ms ease, color 240ms ease;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 54px 54px;
  mask-image: linear-gradient(180deg, transparent 0%, black 18%, black 86%, transparent 100%);
}

body[data-theme="cartoon"] {
  --bg: #f9fbff;
  --panel: rgba(255, 255, 255, 0.88);
  --line: rgba(74, 101, 255, 0.2);
  --text: #24305e;
  --muted: rgba(36, 48, 94, 0.68);
  --cyan: #48c6ff;
  --pink: #ff7ab8;
  --green: #25c76f;
  --amber: #ffbd3d;
  --danger: #ff5d5d;
  --body-bg:
    radial-gradient(circle at 16% 20%, rgba(255, 208, 92, 0.42), transparent 25%),
    radial-gradient(circle at 82% 18%, rgba(116, 210, 255, 0.45), transparent 27%),
    linear-gradient(180deg, #f8fbff 0%, #e8f5ff 55%, #fff2c7 100%);
  --grid-line: rgba(74, 101, 255, 0.07);
  --topbar-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(238, 247, 255, 0.84));
  --surface-bg: rgba(255, 255, 255, 0.52);
  --control-bg: rgba(255, 255, 255, 0.76);
  --control-border: rgba(74, 101, 255, 0.18);
  --control-active: rgba(255, 189, 61, 0.28);
  --hud-bg: rgba(255, 255, 255, 0.78);
  --canvas-sea-top: rgba(91, 206, 255, 0.24);
  --canvas-sea-bottom: rgba(77, 183, 237, 0.36);
  --canvas-wave: rgba(35, 116, 184, 0.22);
  --ship-body: rgba(255, 187, 57, 0.95);
  --ship-sail: rgba(255, 122, 184, 0.88);
  --cannon-main: rgba(74, 101, 255, 0.92);
  --cannon-base: rgba(37, 199, 111, 0.88);
  --ink: #24305e;
}

button,
input {
  font: inherit;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  width: 100%;
  height: 100%;
  padding: 18px;
  gap: 14px;
}

.topbar {
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: var(--topbar-bg);
  box-shadow: 0 0 28px rgba(110, 231, 255, 0.16);
  backdrop-filter: blur(14px);
  border-radius: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 220px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(110, 231, 255, 0.55);
  background: conic-gradient(from 210deg, var(--cyan), var(--pink), var(--amber), var(--cyan));
  box-shadow: 0 0 22px rgba(110, 231, 255, 0.34);
  clip-path: polygon(50% 0, 94% 28%, 78% 86%, 22% 86%, 6% 28%);
}

.brand h1 {
  margin: 0;
  font-size: clamp(22px, 3vw, 36px);
  letter-spacing: 0.08em;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.mode-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 14px;
  color: var(--muted);
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  border-radius: 12px;
  cursor: pointer;
  transition: color 180ms ease, border-color 180ms ease, background 180ms ease;
}

.tab svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab:hover,
.tab:focus-visible,
.tab.is-active {
  color: var(--text);
  border-color: rgba(110, 231, 255, 0.55);
  background: var(--control-active);
  outline: none;
}

.theme-switch {
  display: flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--control-border);
  border-radius: 14px;
  background: var(--control-bg);
}

.theme-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 34px;
  color: var(--muted);
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  transition: color 180ms ease, background 180ms ease;
}

.theme-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-button:hover,
.theme-button:focus-visible,
.theme-button.is-active {
  color: var(--text);
  background: var(--control-active);
  outline: none;
}

.stage-wrap {
  position: relative;
  min-height: 0;
  border: 1px solid var(--line);
  background: var(--surface-bg);
  overflow: hidden;
  border-radius: 22px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 24px 70px rgba(0, 0, 0, 0.24);
}

.hud {
  position: absolute;
  z-index: 4;
  left: 18px;
  right: 18px;
  top: 18px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  pointer-events: none;
}

.hud div {
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--control-border);
  border-radius: 14px;
  background: var(--hud-bg);
  backdrop-filter: blur(12px);
}

.hud span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.hud strong {
  display: block;
  margin-top: 5px;
  font-size: clamp(20px, 3vw, 32px);
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-panel {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

.mode-panel.is-active {
  opacity: 1;
  pointer-events: auto;
}

.float-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.float-stage::after {
  content: "按任意键生成漂浮字符";
  position: absolute;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 32px));
  padding: 12px 16px;
  color: var(--muted);
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--hud-bg);
}

.float-char {
  position: absolute;
  bottom: -58px;
  min-width: 54px;
  padding: 9px 13px;
  color: var(--text);
  font-size: clamp(26px, 5vw, 58px);
  font-weight: 800;
  text-align: center;
  border: 1px solid currentColor;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  text-shadow: 0 0 15px currentColor;
  user-select: none;
  animation: rise var(--life, 7s) cubic-bezier(0.19, 1, 0.22, 1) forwards;
  will-change: transform, opacity;
}

.game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.fleet-banner {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  width: min(620px, calc(100% - 32px));
  padding: 12px 16px;
  color: var(--text);
  text-align: center;
  border: 1px solid rgba(255, 211, 110, 0.28);
  border-radius: 999px;
  background: var(--hud-bg);
  backdrop-filter: blur(12px);
}

.word-panel {
  display: grid;
  place-items: center;
  padding: 96px 18px 22px;
}

.word-scene {
  width: min(920px, 100%);
}

.word-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}

.word-direction {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

.word-direction-button {
  min-height: 40px;
  padding: 0 16px;
  color: var(--muted);
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  border-radius: 999px;
  cursor: pointer;
  transition: color 180ms ease, border-color 180ms ease, background 180ms ease;
}

.word-direction-button:hover,
.word-direction-button:focus-visible,
.word-direction-button.is-active {
  color: var(--text);
  border-color: rgba(125, 255, 136, 0.58);
  background: rgba(125, 255, 136, 0.1);
  outline: none;
}

.word-target {
  min-height: 170px;
  display: grid;
  place-items: center;
  margin: 24px 0 28px;
  font-size: clamp(44px, 10vw, 112px);
  font-weight: 850;
  text-align: center;
  text-shadow: 0 0 28px rgba(110, 231, 255, 0.38), 0 0 44px rgba(255, 93, 184, 0.22);
}

.input-line {
  display: grid;
  gap: 10px;
  color: var(--muted);
}

.input-line input {
  width: 100%;
  padding: 12px 4px 16px;
  color: var(--text);
  font-size: clamp(26px, 5vw, 48px);
  text-align: center;
  background: color-mix(in srgb, var(--panel) 58%, transparent);
  border: 0;
  border-bottom: 3px solid rgba(110, 231, 255, 0.58);
  border-radius: 18px 18px 0 0;
  outline: none;
}

.input-line input:focus {
  border-bottom-color: var(--green);
  box-shadow: 0 16px 26px -24px var(--green);
}

.word-result {
  min-height: 42px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 18px;
  text-align: center;
}

.word-result.ok {
  color: var(--green);
  animation: pulse 420ms ease;
}

.word-result.bad {
  color: var(--danger);
  animation: shake 260ms ease;
}

@keyframes rise {
  0% {
    opacity: 0;
    transform: translate3d(var(--dx, 0), 0, 0) scale(0.72) rotate(-3deg);
  }
  12%,
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate3d(calc(var(--dx, 0) + var(--drift, 0)), calc(-100vh - 160px), 0) scale(1.12) rotate(5deg);
  }
}

@keyframes pulse {
  50% {
    transform: scale(1.04);
    text-shadow: 0 0 24px currentColor;
  }
}

@keyframes shake {
  25% {
    transform: translateX(-8px);
  }
  75% {
    transform: translateX(8px);
  }
}

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

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .mode-tabs,
  .tab {
    width: 100%;
  }

  .top-actions {
    align-items: stretch;
  }

  .tab {
    justify-content: center;
  }

  .theme-switch {
    justify-content: center;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    left: 10px;
    right: 10px;
    top: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mode-panel,
  .tab,
  .theme-button,
  .word-direction-button,
  .float-char,
  .word-result {
    animation: none;
    transition: none;
  }
}
