:root {
  --bg: #141311;
  --panel-bg: rgba(21, 19, 17, 0.9);
  --text: #f2ece2;
  --muted: #d8c8af;
  --border: rgba(247, 232, 201, 0.25);
  --shadow: rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0.01em;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

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

#hud,
#fullscreen-toggle,
#help-toggle,
#overlay-close,
#help-close,
#help-start {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-bg);
  box-shadow: 0 8px 24px var(--shadow);
  backdrop-filter: blur(8px);
}

#hud {
  position: absolute;
  right: 20px;
  bottom: 20px;
  padding: 10px 13px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  z-index: 10;
}

#top-controls {
  position: absolute;
  top: 20px;
  left: 20px;
  display: flex;
  gap: 8px;
  z-index: 30;
}

#fullscreen-toggle,
#help-toggle {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease, border-color 120ms ease;
}

#help-toggle {
  font-size: 20px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0;
}

#fullscreen-toggle:hover,
#help-toggle:hover,
#overlay-close:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(247, 232, 201, 0.45);
}

#fullscreen-toggle:active,
#help-toggle:active,
#overlay-close:active {
  transform: translateY(1px);
}

#fullscreen-toggle:focus-visible,
#help-toggle:focus-visible,
#overlay-close:focus-visible {
  outline: 2px solid rgba(244, 217, 167, 0.9);
  outline-offset: 2px;
}

#overlay {
  position: absolute;
  top: 20px;
  right: 20px;
  width: min(620px, calc(100vw - 40px));
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 16px 16px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-bg);
  box-shadow: 0 10px 30px var(--shadow);
  backdrop-filter: blur(8px);
  z-index: 100;
}

#overlay.hidden {
  display: none;
}

#overlay h2 {
  margin: 10px 0 6px;
  font-size: 22px;
  line-height: 1.2;
  font-weight: 600;
}

#overlay p {
  margin: 0 0 9px;
  line-height: 1.4;
  color: #e6d9c4;
}

#overlay-close {
  float: right;
  margin-left: 10px;
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #f7ecdb;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease, border-color 120ms ease;
}

#fullscreen-toggle svg,
#overlay-close svg,
#help-close svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

#overlay-image {
  display: none;
  width: 100%;
  max-height: min(48vh, 420px);
  height: auto;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.04);
}

#overlay-image.visible {
  display: block;
}

#overlay-year {
  color: #f4d9a7;
  font-weight: 600;
}

#help-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 9, 8, 0.45);
  backdrop-filter: blur(5px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 260ms ease;
  z-index: 110;
}

#help-overlay.hidden {
  display: none;
}

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

#help-card {
  width: min(560px, 100%);
  padding: 20px 20px 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(21, 19, 17, 0.94);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.52);
  transform: translateY(14px) scale(0.98);
  opacity: 0;
  transition: transform 320ms cubic-bezier(0.22, 1, 0.36, 1), opacity 240ms ease;
}

#help-overlay.is-open #help-card {
  transform: translateY(0) scale(1);
  opacity: 1;
}

#help-close {
  float: right;
  margin-left: 10px;
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #f7ecdb;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease, border-color 120ms ease;
}

#help-close:hover,
#help-start:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(247, 232, 201, 0.45);
}

#help-close:active,
#help-start:active {
  transform: translateY(1px);
}

#help-close:focus-visible,
#help-start:focus-visible {
  outline: 2px solid rgba(244, 217, 167, 0.9);
  outline-offset: 2px;
}

#help-kicker {
  margin: 0;
  color: #f4d9a7;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

#help-title {
  margin: 10px 0 8px;
  font-size: 28px;
  line-height: 1.2;
}

#help-subtitle {
  margin: 0;
  color: #e6d9c4;
  line-height: 1.45;
}

#help-list {
  margin: 16px 0 12px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

#help-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(247, 232, 201, 0.2);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}

.help-label {
  color: #f3e7d5;
  font-weight: 600;
}

.help-detail {
  color: #d9cab3;
  text-align: right;
}

#help-note {
  margin: 0;
  color: #cdbca1;
  line-height: 1.45;
}

#help-start {
  margin-top: 14px;
  width: 100%;
  min-height: 44px;
  color: #f5ecdf;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease, border-color 120ms ease;
}

#joystick {
  display: none;
  position: absolute;
  left: 18px;
  bottom: 18px;
  width: 132px;
  height: 132px;
  z-index: 40;
}

#joystick-base {
  position: absolute;
  inset: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-bg);
  box-shadow: 0 8px 24px var(--shadow);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  backdrop-filter: blur(8px);
}

#joystick-stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  transform: translate(-50%, -50%);
  transition: transform 80ms ease-out;
  pointer-events: none;
}

@media (pointer: coarse) {
  #joystick {
    display: block;
  }

  #hud {
    max-width: calc(100vw - 170px);
    font-size: 11px;
  }

  #help-title {
    font-size: 24px;
  }

  #help-list li {
    display: block;
  }

  .help-detail {
    display: block;
    margin-top: 3px;
    text-align: left;
  }
}
