:root {
  --ink: #273847;
  --muted: #667784;
  --paper: #fff9e8;
  --panel: rgba(255, 252, 239, 0.9);
  --teal: #2f8f9d;
  --teal-dark: #226b78;
  --coral: #dd7d58;
  --yellow: #f4c867;
  --leaf: #6f9f6a;
  --line: rgba(63, 67, 54, 0.14);
  --shadow: 0 18px 42px rgba(67, 54, 38, 0.15);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background:
    linear-gradient(90deg, rgba(255,255,255,.34) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255,255,255,.22) 1px, transparent 1px),
    radial-gradient(circle at 16% 12%, rgba(244, 200, 103, 0.48), transparent 20rem),
    radial-gradient(circle at 84% 18%, rgba(47, 143, 157, 0.22), transparent 18rem),
    linear-gradient(180deg, #fff3d2 0%, #f3dfb4 44%, #dfe9cf 100%);
  background-size: 36px 36px, 36px 36px, auto, auto, auto;
  overflow-x: hidden;
}

button {
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  min-height: 46px;
  padding: 12px 18px;
  transition: transform 0.14s ease, box-shadow 0.14s ease, opacity 0.14s ease;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

.app {
  display: grid;
  gap: 8px;
  grid-template-rows: auto auto;
  margin: 0 auto;
  max-width: none;
  padding: 0;
  width: 100%;
}

.topbar,
.game-shell,
.side-panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.topbar {
  align-items: end;
  border-radius: 24px;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr minmax(470px, 0.72fr);
  padding: 12px 16px;
  position: relative;
}

.eyebrow {
  color: #9b6932;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 6px;
}

h1 {
  font-size: clamp(28px, 3.6vw, 46px);
  line-height: 1.02;
  margin: 0;
}

.intro {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  margin: 8px 0 0;
}

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

.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 8px 18px rgba(24, 50, 71, 0.08);
  min-width: 0;
  padding: 10px 12px;
}

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

.stat strong {
  display: block;
  font-size: 26px;
  line-height: 1.1;
  margin-top: 4px;
}

.layout {
  align-items: start;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1.8fr) minmax(300px, 0.52fr);
  min-height: 0;
}

.game-shell {
  border-radius: 22px;
  display: grid;
  grid-template-rows: 430px auto;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.game-shell::before {
  background: linear-gradient(90deg, #2f8f9d, #f4c867, #dd7d58, #6f9f6a);
  content: "";
  height: 6px;
  left: 0;
  position: absolute;
  right: 0;
  top: 0;
  z-index: 2;
}

.canvas-wrap {
  background:
    radial-gradient(circle at 20% 18%, rgba(255,255,255,.65), transparent 9rem),
    linear-gradient(180deg, #ffe5ae 0%, #f9dca6 38%, #d7d9b1 39%, #b7c68f 100%);
  height: 430px;
  min-height: 0;
  position: relative;
}

canvas {
  display: block;
  height: 100%;
  width: 100%;
}

.jump-fab {
  background: linear-gradient(135deg, var(--teal), #4fb5ad);
  bottom: 20px;
  box-shadow: 0 14px 24px rgba(47, 143, 157, 0.32);
  color: #fff;
  display: none;
  font-size: 22px;
  height: 82px;
  position: absolute;
  right: 18px;
  width: 82px;
  z-index: 2;
}

.hud {
  align-items: center;
  background: rgba(255, 255, 255, 0.92);
  border-top: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 10px 12px;
}

.actions {
  display: flex;
  gap: 10px;
}

.primary {
  background: linear-gradient(135deg, var(--teal), var(--teal-dark));
  box-shadow: 0 10px 20px rgba(48, 169, 156, 0.26);
  color: #fff;
}

.secondary {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
}

.danger {
  background: #fff4ef;
  border: 1px solid rgba(221, 125, 88, 0.34);
  color: #a44b31;
}

.message {
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
  line-height: 1.6;
  min-width: 220px;
  text-align: right;
}

.side-panel {
  align-content: start;
  border-radius: 22px;
  display: grid;
  gap: 10px;
  max-height: 620px;
  min-height: 0;
  overflow: auto;
  padding: 12px;
}

.side-panel section {
  background: rgba(255, 253, 245, 0.84);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
}

.side-panel h2 {
  font-size: 16px;
  margin: 0 0 8px;
}

.plate-progress {
  display: grid;
  gap: 6px;
}

.group-row {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 28px 1fr auto;
}

.group-icon {
  align-items: center;
  border-radius: 10px;
  color: #fff;
  display: flex;
  font-size: 18px;
  font-weight: 900;
  height: 28px;
  justify-content: center;
  width: 28px;
}

.group-name {
  font-size: 13px;
  font-weight: 800;
  min-width: 0;
}

.group-count {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  min-width: 38px;
  padding: 4px 8px;
  text-align: center;
}

.tips {
  color: var(--muted);
  display: grid;
  gap: 5px;
  line-height: 1.45;
  margin: 0;
  padding-left: 20px;
}

.knowledge p {
  color: var(--muted);
  font-weight: 750;
  line-height: 1.7;
  margin: 0;
}

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

.legend-column {
  min-width: 0;
}

.legend-column h3 {
  color: var(--teal-dark);
  font-size: 13px;
  margin: 0 0 6px;
}

.legend-list {
  display: grid;
  gap: 8px;
}

.legend-item {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  display: grid;
  gap: 8px;
  grid-template-columns: 34px 1fr;
  min-width: 0;
  padding: 8px;
}

.legend-icon {
  align-items: center;
  border-radius: 12px;
  display: flex;
  font-size: 20px;
  height: 34px;
  justify-content: center;
  width: 34px;
}

.obstacle-item .legend-icon {
  background: #fff1ea;
}

.power-item .legend-icon {
  background: #edf8f6;
}

.legend-item strong {
  display: block;
  font-size: 12px;
  line-height: 1.3;
}

.legend-item p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  margin: 2px 0 0;
}

.result-dialog {
  background: transparent;
  border: 0;
  max-width: min(92vw, 620px);
  padding: 0;
}

.result-dialog::backdrop {
  background: rgba(24, 50, 71, 0.36);
  backdrop-filter: blur(3px);
}

.result-card {
  background: var(--paper);
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 22px;
}

.result-card h2 {
  font-size: 28px;
  margin: 0 0 8px;
}

.result-card p {
  color: var(--muted);
  line-height: 1.7;
}

.result-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 16px 0;
}

.result-item {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  display: flex;
  gap: 10px;
  min-width: 0;
  padding: 10px;
}

.result-tip {
  background: rgba(48, 169, 156, 0.12);
  border-radius: 14px;
  color: var(--teal-dark) !important;
  font-weight: 800;
  padding: 12px;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

@media (max-width: 980px) {
  .app {
    min-height: auto;
    padding: 0;
  }

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

  .game-shell {
    min-height: 0;
  }

  .side-panel {
    max-height: none;
    overflow: visible;
  }

  .message {
    text-align: left;
  }
}

@media (max-width: 640px) {
  .app {
    gap: 10px;
    padding: 8px;
  }

  .topbar,
  .game-shell,
  .side-panel {
    border-radius: 18px;
  }

  .stats {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .stat {
    padding: 7px 5px;
  }

  .stat span {
    font-size: 10px;
  }

  .stat strong {
    font-size: 18px;
  }

  .game-shell {
    grid-template-rows: 420px auto;
    min-height: 0;
  }

  .canvas-wrap {
    height: 420px;
    min-height: 0;
  }

  .jump-fab {
    display: block;
  }

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

  .actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .actions button {
    font-size: 14px;
    padding-left: 8px;
    padding-right: 8px;
  }

  .message {
    min-width: 0;
  }

  .legend-columns {
    grid-template-columns: 1fr;
  }

  .result-grid {
    grid-template-columns: 1fr;
  }

}
