/* Reset & Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #0b0f12;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: #e6ebed;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #0b0f12;
}

/* Canvas Viewport: Default 720p (1280x720, exact 2x integer scale) */
#canvas-wrapper {
  position: relative;
  width: 1280px;
  height: 720px;
  max-width: 100vw;
  max-height: 100vh;
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid #1c2630;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.65);
}

/* On smaller windows (laptops or small viewports), scale down preserving 16:9 */
@media (max-width: 1280px), (max-height: 720px) {
  #canvas-wrapper {
    width: 100vw;
    height: 56.25vw;
    max-width: 177.78vh;
    max-height: 100vh;
  }
}

/* Fullscreen mode expands to fill the monitor while preserving 16:9 */
:fullscreen #canvas-wrapper,
:-webkit-full-screen #canvas-wrapper,
body.is-fullscreen #canvas-wrapper {
  width: 100vw;
  height: 56.25vw;
  max-width: 177.78vh;
  max-height: 100vh;
  border-radius: 0;
  border: none;
  box-shadow: none;
}

#pixel-canvas, #webgl-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#webgl-canvas {
  pointer-events: none;
}

/* HUD Overlay */
#hud-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px 28px;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 10;
}

#hud-overlay.hud-hidden {
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
}

#hud-overlay.hud-hidden #top-bar,
#hud-overlay.hud-hidden #bottom-bar {
  pointer-events: none;
}

#hud-overlay.hud-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: none;
}

#hud-overlay.hud-visible #top-bar,
#hud-overlay.hud-visible #bottom-bar {
  pointer-events: auto;
}

/* Zen Mode Active */
body.zen-active #hud-overlay {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translateY(4px);
}

/* Top Bar - 3-Column Balanced Grid with Centered Calendar Strip */
#top-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  pointer-events: auto;
  width: 100%;
}

.top-spacer {
  justify-self: flex-start;
}

.calendar-pill {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 9px;
  background: #0d1319;
  border: 1px solid #1e2a36;
  padding: 6px 14px;
  border-radius: 4px;
  font-family: "Courier New", Courier, monospace;
  font-size: 12px;
  color: #cfdbe3;
  box-shadow: 0 2px 0 #06090d;
}

.pixel-clock {
  font-family: "Courier New", Courier, monospace;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: #f2f7fa;
}

.dot-separator {
  color: #435462;
}

.local-time-sub {
  font-size: 11px;
  color: #6e8494;
  margin-left: 2px;
}

.melody-glyph {
  font-size: 11px;
  color: #3b4e5c;
  margin-left: 5px;
  user-select: none;
  transition: color 0.3s ease, text-shadow 0.3s ease, transform 0.3s ease;
}

.melody-glyph.glowing {
  color: #ffda73;
  text-shadow: 0 0 6px rgba(255, 218, 115, 0.85);
  transform: scale(1.2);
}

#season-badge {
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  transition: transform 0.12s, filter 0.12s;
}

#season-badge:hover {
  filter: brightness(1.25);
}

.badge-spring { background: #163622; color: #8ee0a5; border: 1px solid #235435; }
.badge-summer { background: #133a20; color: #7de094; border: 1px solid #1f5731; }
.badge-autumn { background: #3d2812; color: #e8a96c; border: 1px solid #613f1c; }
.badge-winter { background: #152b3d; color: #90c2e8; border: 1px solid #23435e; }

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

/* Icon Buttons */
.icon-button {
  background: #0d1319;
  border: 1px solid #1e2a36;
  color: #9cb0bf;
  width: 30px;
  height: 30px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.12s ease;
  box-shadow: 0 2px 0 #06090d;
}

.icon-button:hover {
  background: #17222d;
  color: #ffffff;
  border-color: #2e4052;
}

.icon-button:active {
  background: #111a22;
  transform: translateY(1px);
  box-shadow: 0 1px 0 #06090d;
}

#chime-toggle.active {
  color: #e5b95c;
  border-color: #664d1c;
  background: #181c1c;
}

#weather-btn.active {
  color: #69b6eb;
  border-color: #275475;
  background: #101921;
}

#wildlife-toggle.wildlife-quiet {
  color: #a7cb74;
  border-color: #273e21;
  background: #111d13;
}

#wildlife-toggle.wildlife-normal {
  color: #79e396;
  border-color: #245233;
  background: #0f271a;
  box-shadow: 0 0 6px rgba(121, 227, 150, 0.25);
}

#wildlife-toggle.wildlife-off {
  color: #4a5d6a;
  border-color: #1a252f;
  background: #0d141b;
  opacity: 0.65;
}

.hidden {
  display: none !important;
}

/* Subtle First-Load Audio Card */
.audio-prompt-card {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0d141b;
  border: 1px solid #223547;
  box-shadow: 0 2px 0 #06090d, 0 4px 16px rgba(0, 0, 0, 0.6);
  padding: 6px 14px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  color: #d1e2ee;
  pointer-events: none;
  z-index: 25;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.audio-prompt-card.dismissed {
  opacity: 0;
  transform: translate(-50%, 8px);
}

.audio-prompt-icon {
  color: #8ed274;
}

/* Quiet Bamboo Factoid Overlay (Region x: 150-470, y: 270-320 in native 640x360 coords) */
#factoid-container {
  position: absolute;
  left: 50%;
  top: 75%;
  transform: translateX(-50%);
  width: 47%;
  max-width: 47%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 7px;
  pointer-events: none;
  z-index: 8;
  opacity: 0;
  transition: opacity 1s ease;
}

#factoid-container.factoid-visible {
  opacity: 1;
}

#factoid-container.factoid-fading {
  opacity: 0;
  transition: opacity 2s ease;
}

#factoid-container.factoid-hidden {
  opacity: 0;
  pointer-events: none;
}

.factoid-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  filter: drop-shadow(0 1px 2px #04080a) drop-shadow(0 0 1px #04080a);
}

#factoid-text {
  font-family: "Courier New", Courier, monospace;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: 0.2px;
  color: rgba(247, 245, 238, 0.82);
  text-align: center;
  text-shadow: 
    0 1px 3px #04080a,
    0 0 2px #04080a,
    1px 1px 0 #04080a,
    -1px -1px 0 #04080a,
    1px -1px 0 #04080a,
    -1px 1px 0 #04080a;
}

/* Bottom Controls - Corner Aligned */
#bottom-bar {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: flex-end;
  width: 100%;
  pointer-events: none;
}

/* Focus Panel (Bottom-Left Corner) - Calibrated to match Speed Dial visual scale & border style */
.focus-panel {
  pointer-events: auto;
  background: #0d1319;
  border: 1px solid #1e2a36;
  border-radius: 4px;
  padding: 8px 12px 6px;
  box-shadow: 0 2px 0 #06090d;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: 128px;
  height: 140px;
}

.focus-header {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.focus-tag {
  font-family: "Courier New", Courier, monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 3px;
  background: #163622;
  color: #8ee0a5;
  border: 1px solid #235435;
  text-transform: uppercase;
}

.focus-tag.rest {
  background: #2e1d3d;
  color: #c4a5e6;
  border-color: #4a2f63;
}

.focus-display-box {
  background: #070b0f;
  border: 1px solid #16202a;
  border-radius: 3px;
  padding: 8px 12px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.6);
}

.focus-panel .pixel-clock {
  font-family: "Courier New", Courier, monospace;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #e6ebed;
}

.focus-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  width: 100%;
}

.mini-btn {
  background: #151d26;
  border: 1px solid #253342;
  color: #cfdbe3;
  border-radius: 3px;
  width: 44px;
  height: 24px;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s ease;
  box-shadow: 0 1px 0 #080c10;
}

.mini-btn:hover {
  background: #212e3b;
  color: #ffffff;
  border-color: #354a5e;
}

.mini-btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

.focus-readout {
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  font-weight: 600;
  color: #9cb0bf;
  letter-spacing: 0.3px;
  text-align: center;
}

/* Center Info Tip */
.info-tip {
  pointer-events: auto;
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  color: #687f91;
  background: rgba(13, 19, 25, 0.85);
  border: 1px solid rgba(30, 42, 54, 0.75);
  padding: 4px 12px;
  border-radius: 4px;
  margin-bottom: 6px;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.info-tip.auto-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
}

#hud-overlay:hover .info-tip.auto-hidden {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* Speed Dial (Bottom-Right Corner) */
.knob-panel {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #0d1319;
  border: 1px solid #1e2a36;
  border-radius: 4px;
  padding: 8px 12px 6px;
  box-shadow: 0 2px 0 #06090d;
}

.knob-assembly {
  position: relative;
  width: 104px;
  height: 104px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.dial-marks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.mark {
  position: absolute;
  font-family: "Courier New", Courier, monospace;
  font-size: 10px;
  font-weight: 600;
  color: #536778;
  cursor: pointer;
  pointer-events: auto;
  transition: color 0.12s ease;
}

.mark.active {
  color: #e5b95c;
  font-weight: 700;
}

/* 5 Polar positions for -120deg to +120deg */
.m-1x    { left: 6px;  bottom: 14px; }
.m-60x   { left: 4px;  top: 22px; }
.m-360x  { left: 50%;  top: 2px; transform: translateX(-50%); }
.m-1440x { right: 4px; top: 22px; }
.m-8640x { right: 6px; bottom: 14px; }

/* Wooden Bamboo Dial Knob */
.wooden-knob {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #855734, #52331c 65%, #2a190e 100%);
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.6),
    0 1px 3px rgba(0, 0, 0, 0.4),
    inset 0 1px 3px rgba(255, 220, 180, 0.25),
    inset 0 -2px 4px rgba(0, 0, 0, 0.6);
  cursor: grab;
  outline: none;
  border: 2px solid #845e42;
}

.wooden-knob:active {
  cursor: grabbing;
}

.knob-texture {
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: repeating-radial-gradient(circle at 45% 45%, rgba(138, 86, 52, 0.4) 0, rgba(138, 86, 52, 0.4) 3px, rgba(82, 48, 26, 0.5) 4px, rgba(82, 48, 26, 0.5) 6px);
  pointer-events: none;
}

.knob-pointer {
  position: absolute;
  top: 4px;
  left: 50%;
  width: 3px;
  height: 11px;
  margin-left: -1.5px;
  background: #fdf2d9;
  border-radius: 1px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.knob-brass-cap {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ebd08c, #a88339 60%, #634718 100%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  border: 1px solid #735420;
}

.speed-readout {
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  font-weight: 600;
  color: #9cb0bf;
  margin-top: 4px;
  letter-spacing: 0.3px;
}

/* Responsive alignment on compact screens */
@media (max-width: 820px) {
  #top-bar {
    grid-template-columns: 1fr;
    gap: 8px;
    justify-items: center;
  }
  .header-actions {
    justify-content: center;
  }
}
