:root {
  --bg-sky-top: #87d7ff;
  --bg-sky-mid: #a9ebff;
  --bg-sky-bottom: #f4fff6;
  --ink: #1a2736;
  --panel-bg: rgba(255, 255, 255, 0.88);
  --panel-border: rgba(10, 45, 80, 0.15);
  --pill-bg: rgba(255, 255, 255, 0.85);
  --pill-border: rgba(3, 46, 87, 0.2);
  --accent: #ff6d3a;
  --ok: #00a96e;
  --warn: #c98500;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  color: var(--ink);
  font-family: "Trebuchet MS", "Avenir Next", "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  background: linear-gradient(
    180deg,
    var(--bg-sky-top) 0%,
    var(--bg-sky-mid) 45%,
    var(--bg-sky-bottom) 100%
  );
}

#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  touch-action: none;
}

.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.hud-top {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  pointer-events: none;
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
  border-radius: 999px;
  min-width: 88px;
  padding: 8px 12px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  box-shadow: 0 5px 18px rgba(8, 42, 71, 0.12);
}

.pill span {
  font-size: 12px;
  opacity: 0.75;
}

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

.progress-wrap {
  margin-top: 10px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 9px 12px 10px;
  box-shadow: 0 8px 22px rgba(10, 44, 73, 0.12);
}

.progress-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  margin-bottom: 8px;
}

.progress-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(17, 82, 121, 0.18);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #00a96e 0%, #ffb33d 60%, #ff6d3a 100%);
  transition: width 120ms linear;
}

.toast {
  margin-top: 8px;
  min-height: 20px;
  font-size: 13px;
  color: #17344a;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}

.panel {
  position: fixed;
  width: min(92vw, 560px);
  max-height: calc(100vh - 30px);
  overflow: auto;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  padding: 18px 18px 16px;
  border-radius: 18px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  box-shadow: 0 18px 48px rgba(0, 26, 52, 0.28);
  backdrop-filter: blur(6px);
}

.panel h1,
.panel h2 {
  margin: 0;
  font-size: clamp(24px, 3.3vw, 34px);
}

.panel-sub {
  margin: 10px 0 12px;
  line-height: 1.45;
  opacity: 0.92;
}

.field {
  display: block;
  margin-bottom: 10px;
}

.field span {
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
  opacity: 0.8;
}

.draw-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
}

#drawPad {
  width: 100%;
  height: 168px;
  display: block;
  border-radius: 12px;
  border: 1px solid rgba(16, 67, 107, 0.28);
  background: linear-gradient(180deg, #ffffff 0%, #f0fbff 100%);
  touch-action: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
}

.ghost-btn {
  width: auto !important;
  min-width: 96px;
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid rgba(22, 71, 109, 0.35);
  background: rgba(255, 255, 255, 0.84);
  color: #1f4f74;
  box-shadow: none;
  font-size: 14px;
}

input,
select,
button {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(18, 66, 103, 0.25);
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
}

input,
select {
  background: rgba(255, 255, 255, 0.92);
  color: #17344b;
}

button {
  cursor: pointer;
  color: #fff;
  font-weight: 700;
  background: linear-gradient(90deg, #ff6d3a 0%, #ff8a3d 50%, #f5532f 100%);
  box-shadow: 0 8px 20px rgba(255, 88, 40, 0.35);
  transition: transform 120ms ease, filter 120ms ease;
  touch-action: manipulation;
}

button:hover {
  filter: brightness(1.03);
}

button:active {
  transform: translateY(1px) scale(0.997);
}

.formula {
  margin-top: 12px;
  padding: 10px 11px;
  border-radius: 12px;
  background: rgba(9, 67, 106, 0.08);
  font-size: 13px;
  line-height: 1.4;
}

.tips {
  margin-top: 10px;
  font-size: 13px;
  opacity: 0.88;
}

.synth-result {
  margin: 10px 0 0;
  font-size: 14px;
  font-weight: 700;
  color: #144869;
}

.result-actions {
  margin-top: 12px;
  display: flex;
  gap: 10px;
}

.result-actions button {
  flex: 1;
}

.hidden {
  display: none;
}

@media (max-width: 700px) {
  .pill {
    min-width: 78px;
    padding: 7px 10px;
  }

  .pill strong {
    font-size: 15px;
  }

  .progress-wrap {
    margin-top: 8px;
  }

  .draw-wrap {
    grid-template-columns: 1fr;
  }
}
