@import url("https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&display=swap");

:root {
  --bg-top: #e7f2d7;
  --bg-bottom: #f6efd4;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-solid: #ffffff;
  --panel-border: #cadabc;
  --text: #2f3b2b;
  --muted: #546153;
  --accent: #2f7a48;
  --button: #f2b24d;
  --button-text: #3c2c11;
  --danger: #d6796c;
  --shadow: 0 18px 30px rgba(43, 66, 40, 0.15);
  --radius: 24px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Fredoka", "Trebuchet MS", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.7), transparent 45%),
    radial-gradient(circle at 80% 10%, rgba(255, 255, 255, 0.6), transparent 40%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

button {
  font-family: inherit;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 16px 120px;
  position: relative;
}

.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hud-block {
  font-size: 20px;
  font-weight: 700;
}

.hud-line {
  line-height: 1.1;
}

.hud-sub {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  margin-top: 2px;
}

.hud-center {
  text-align: center;
  font-size: 18px;
  color: var(--muted);
}

.icon-btn {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  border: 2px solid var(--panel-border);
  background: var(--panel-solid);
  font-size: 22px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.icon-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.game-wrapper {
  flex: 1;
  display: grid;
  place-items: center;
  position: relative;
}

.canvas-shell {
  width: min(980px, 100%);
  height: clamp(320px, 60vh, 560px);
  border-radius: 28px;
  border: 3px solid #d5e0c9;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.2));
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.toast {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) translateY(12px);
  padding: 12px 20px;
  background: var(--panel-solid);
  border-radius: 999px;
  border: 2px solid var(--panel-border);
  font-size: 18px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  box-shadow: var(--shadow);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) translateY(0);
}

.base-panel {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  width: min(860px, calc(100% - 40px));
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-height: min(70vh, 520px);
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 6;
}

.base-panel.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.base-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
}

.base-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.base-card {
  background: var(--panel-solid);
  border-radius: 18px;
  border: 2px solid var(--panel-border);
  padding: 12px;
}

.base-label {
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--muted);
}

.base-row {
  display: flex;
  justify-content: space-between;
  font-size: 18px;
  padding: 4px 0;
}

.base-info {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 18px;
  border: 2px solid var(--panel-border);
  background: var(--panel-solid);
  display: grid;
  gap: 6px;
}

.base-hint {
  font-size: 15px;
  color: var(--muted);
  text-align: center;
}

.pet-panel {
  margin-top: 12px;
  padding: 12px;
  border-radius: 18px;
  border: 2px solid var(--panel-border);
  background: var(--panel-solid);
  display: grid;
  gap: 10px;
}

.pet-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pet-option {
  min-height: 48px;
  padding: 8px 12px;
  border-radius: 14px;
  border: 2px solid var(--panel-border);
  background: #ffffff;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
}

.pet-option.active {
  border-color: var(--accent);
  background: #fdf2d6;
}

.pet-option:focus-visible,
.pet-action:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.pet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.pet-action {
  min-height: 48px;
  padding: 8px 14px;
  border-radius: 14px;
  border: 2px solid var(--panel-border);
  background: #f7efd7;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
}

.pet-action:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.pet-empty {
  font-size: 15px;
  color: var(--muted);
}

.pet-pat-fab {
  position: fixed;
  left: 16px;
  bottom: 96px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  font-size: 24px;
  cursor: pointer;
  z-index: 7;
  touch-action: none;
}

.pet-pat-fab:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.is-hidden {
  display: none !important;
}

.base-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.btn {
  min-height: 56px;
  padding: 12px 20px;
  border: none;
  border-radius: 18px;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
}

.btn.primary {
  background: var(--button);
  color: var(--button-text);
}

.btn.danger {
  background: var(--danger);
  color: #ffffff;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.cost {
  font-size: 16px;
  color: var(--muted);
}

.joystick {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 4;
  touch-action: none;
  user-select: none;
}

.joystick-base {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: 2px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow);
  position: relative;
  touch-action: none;
}

.joystick-knob {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.95);
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  box-shadow: var(--shadow);
  touch-action: none;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(25, 40, 28, 0.4);
  z-index: 10;
}

.modal.hidden {
  display: none;
}

.modal-content {
  width: min(480px, 100%);
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-header h2 {
  margin: 0;
  font-size: 24px;
}

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toggle {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 18px;
  background: var(--panel-solid);
  border: 2px solid var(--panel-border);
  font-size: 18px;
  cursor: pointer;
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.toggle-ui {
  width: 54px;
  height: 30px;
  border-radius: 999px;
  background: #c8d4c0;
  position: relative;
}

.toggle-ui::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.2s ease;
}

.toggle input:checked + .toggle-ui {
  background: var(--accent);
}

.toggle input:checked + .toggle-ui::after {
  transform: translateX(24px);
}

.toggle input:focus-visible + .toggle-ui {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.reset-group {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hint {
  font-size: 14px;
  color: var(--muted);
}

.no-animations *,
.no-animations *::before,
.no-animations *::after {
  animation: none !important;
  transition: none !important;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

@media (max-width: 720px) {
  .hud {
    grid-template-columns: 1fr auto auto;
  }

  .hud-block {
    font-size: 18px;
  }

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

  .hud-sub {
    font-size: 12px;
  }

  .icon-btn {
    width: 48px;
    height: 48px;
  }

  .pet-option,
  .pet-action {
    font-size: 16px;
  }

  .joystick {
    right: 12px;
    bottom: 12px;
  }

  .pet-pat-fab {
    left: 12px;
    bottom: 88px;
    width: 52px;
    height: 52px;
    font-size: 22px;
  }

  .canvas-shell {
    height: clamp(300px, 55vh, 520px);
  }

  .base-panel {
    bottom: 110px;
    width: min(760px, calc(100% - 24px));
    padding: 12px;
    max-height: min(62vh, 420px);
  }
}

@media (max-width: 520px) {
  .app {
    padding: 12px 12px 140px;
  }

  .base-panel {
    bottom: 118px;
    width: calc(100% - 20px);
    padding: 10px;
    max-height: min(58vh, 360px);
  }

  .btn {
    font-size: 18px;
  }

  .pet-option,
  .pet-action {
    min-height: 44px;
    padding: 6px 10px;
  }

  .pet-pat-fab {
    left: 12px;
    bottom: 78px;
    width: 48px;
    height: 48px;
    font-size: 20px;
  }

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