:root {
  --ink: #3b302a;
  --paper: #f7f3ec;
  --paper-2: #efe8dc;
  --accent: #c8312b;
  --green: #2f8a4e;
  --shadow: 3px 3px 0 var(--ink);
  --controls-height: 60px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #ece6dc;
  color: var(--ink);
  font: 13px/1.4 'IBM Plex Mono', ui-monospace, monospace;
}
#c {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  image-rendering: pixelated;
  cursor: grab;
  touch-action: none;
}
#c.dragging { cursor: grabbing; }
#c.hovering { cursor: pointer; }

#speech-bubbles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  --bubble-paper: #f7f3ec;
  --bubble-ink: #3b302a;
  --bubble-radius: 2px;
}
.speech-bubble {
  position: absolute;
  transform: translate(-50%, -100%);
  padding: 4px 7px;
  border: 2px solid var(--bubble-ink);
  border-radius: var(--bubble-radius);
  background: var(--bubble-paper);
  color: var(--bubble-ink);
  box-shadow: 2px 2px 0 var(--bubble-ink);
  font: 10px/1.4 'Silkscreen', monospace;
  white-space: nowrap;
}
.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: calc(50% - 4px);
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--bubble-ink);
  border-bottom: 2px solid var(--bubble-ink);
  background: var(--bubble-paper);
  transform: rotate(45deg);
}
[data-theme='original'] #speech-bubbles { --bubble-radius: 5px; }
[data-theme='poster'] #speech-bubbles { --bubble-paper: #fff3d6; --bubble-ink: #382b30; }
[data-theme='snes'] #speech-bubbles { --bubble-paper: #ffffff; --bubble-ink: #262b44; --bubble-radius: 0px; }
[data-theme='cozy'] #speech-bubbles { --bubble-paper: #fff4e8; --bubble-ink: #80676b; --bubble-radius: 8px; }
[data-theme='pico8'] #speech-bubbles { --bubble-paper: #fff1e8; --bubble-ink: #1d2b53; --bubble-radius: 0px; }
[data-theme='gameboy'] #speech-bubbles { --bubble-paper: #9bbc0f; --bubble-ink: #0f380f; --bubble-radius: 0px; }
[data-theme='illustrated'] #speech-bubbles { --bubble-paper: #fff2d8; --bubble-ink: #514338; }
[data-theme='geometric'] #speech-bubbles { --bubble-paper: #f9f5ed; --bubble-ink: #426779; --bubble-radius: 7px; }
[data-theme='geometric'] .speech-bubble { font-family: 'IBM Plex Mono', monospace; box-shadow: none; }

.panel {
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: var(--shadow);
}

#today { position:fixed;top:70px;right:max(16px, env(safe-area-inset-right));padding:6px 8px;max-width:180px;font-size:10px;box-shadow:2px 2px 0 var(--ink); }
#today[hidden] { display:none; }
.sr-only { position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0; }
#today-weather { font-size:11px;font-weight:500; }
.today-sun { display:flex;gap:8px;padding-top:2px;white-space:nowrap; }
.today-source { font-size:8px;opacity:.7;margin-top:2px; }
.today-source a { color:inherit; }
@media(max-width:640px) { #today{top:calc(max(12px, env(safe-area-inset-top)) + 46px);right:max(12px, env(safe-area-inset-right));} }

#hud {
  position: fixed;
  top: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  pointer-events: none;
}
.brand { display: flex; flex-direction: column; }
.logo {
  font-family: 'Silkscreen', monospace;
  font-size: 22px;
  letter-spacing: 1px;
  line-height: 1;
  color: var(--ink);
  text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.6);
}
.place { font-size: 12px; opacity: 0.8; margin-top: 4px; }
.location-picker { display:flex; align-items:center; gap:7px; margin-top:8px; font-size:10px; pointer-events:auto; color:var(--ink); background:var(--paper); padding:4px 6px; border:1px solid var(--ink); box-shadow:2px 2px 0 var(--ink); }
.location-picker select { min-width:0; width:100%; font:inherit; font-size:11px; color:var(--ink); background:var(--paper); border:0; padding:3px 2px; cursor:pointer; }
.map-credit { position:fixed; left:12px; bottom:5px; font-size:8px; color:var(--ink); background:var(--paper); padding:1px 3px; }
.srcItem a { color:inherit; font-size:10px; }
#views { display:flex; gap:5px; margin-top:8px; pointer-events:auto; }
#views[hidden] { display:none; }
#views button { font:10px 'IBM Plex Mono',monospace; padding:5px 7px; color:var(--ink); background:var(--paper); border:1px solid var(--ink); cursor:pointer; }
#views button:hover { background:var(--paper-2); }
@media(pointer:coarse) { #views button { min-height:40px; } }
@media(max-width:640px) { .location-picker { max-width:245px; } .location-picker select { min-height:32px; font-size:10px; } }
.night .logo, .night .place { color: #f2ead8; text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.4); }
.clock {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  font-family: 'Silkscreen', monospace;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#log {
  position: fixed;
  top: 150px;
  right: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;
  max-width: min(340px, calc(100vw - 32px));
}
#log li {
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
  padding: 4px 8px;
  font-size: 12px;
  transition: opacity 0.6s, transform 0.3s;
  animation: pop 0.25s ease-out;
}
#log li.fade { opacity: 0; transform: translateX(8px); }
#log li .t { opacity: 0.55; margin-right: 6px; }
#log li.open { border-color: var(--green); box-shadow: 2px 2px 0 var(--green); }
#log li.close { opacity: 0.85; }
@keyframes pop { from { transform: translateY(-6px); opacity: 0; } }

#controls {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  max-width: calc(100vw - 32px);
  flex-wrap: wrap;
  justify-content: center;
}
#controls button {
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  background: var(--paper-2);
  border: 2px solid var(--ink);
  padding: 3px 8px;
  min-width: 32px;
  cursor: pointer;
}
#controls button:hover { background: #fff; }
#controls button.on { background: var(--ink); color: var(--paper); }
#controls .seg { display: flex; }
#controls .seg button + button { border-left: 0; }
#controls .sep { width: 1px; height: 20px; background: var(--ink); opacity: 0.25; margin: 0 2px; }
#controls input[type=range] { accent-color: var(--accent); }
#controls select {
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  background: var(--paper-2);
  border: 2px solid var(--ink);
  padding: 2px 4px;
  cursor: pointer;
}
#time { width: 130px; }
#vol { width: 70px; }
#mobile-gestures { display: none; }
@media (max-width: 640px), (pointer: coarse) {
  #mobile-gestures {
    display: grid;
    flex: 1 0 100%;
    order: 2;
    gap: 2px;
    padding-top: 6px;
    border-top: 1px solid rgba(59, 48, 42, 0.2);
    text-align: center;
    font-size: 10px;
    line-height: 1.4;
  }
}

#hint {
  position: fixed;
  left: 50%;
  top: 72px;
  transform: translateX(-50%);
  font-size: 12px;
  background: rgba(247, 243, 236, 0.85);
  padding: 3px 10px;
  border-radius: 2px;
  pointer-events: none;
  transition: opacity 1s;
  white-space: nowrap;
}
#hint.gone { opacity: 0; }
.touch-hint { display: none; }
button, select, input { touch-action: manipulation; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

#tip {
  position: fixed;
  pointer-events: none;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
  padding: 6px 9px;
  max-width: 280px;
  font-size: 12px;
  z-index: 5;
}
#tip b { display: block; font-size: 13px; }
#tip .sub { display: block; margin-top: 2px; }
#tip .src { display: block; margin-top: 4px; opacity: 0.6; font-size: 11px; }

#inspector {
  position: fixed;
  top: 76px;
  right: 16px;
  bottom: 76px;
  width: min(380px, calc(100vw - 32px));
  overflow: auto;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: var(--shadow);
  padding: 14px 16px 18px;
  z-index: 6;
}
#closeInspector {
  position: sticky;
  top: 0;
  float: right;
  font: inherit;
  font-size: 18px;
  line-height: 1;
  background: var(--paper-2);
  border: 2px solid var(--ink);
  width: 28px;
  height: 28px;
  cursor: pointer;
}
#inspector h2 { font-family: 'Silkscreen', monospace; font-size: 16px; font-weight: 400; margin: 0 0 4px; }
#inspector h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; margin: 16px 0 6px; opacity: 0.7; }
#inspector p { margin: 4px 0; }
#inspector pre {
  background: var(--paper-2);
  border: 1px solid rgba(59, 48, 42, 0.25);
  padding: 8px;
  font-size: 11px;
  overflow: auto;
  max-height: 320px;
  white-space: pre-wrap;
  word-break: break-word;
}
#inspector .srcs { display: grid; gap: 10px; }
#inspector .srcItem { display: grid; grid-template-columns: 84px 1fr; gap: 10px; align-items: start; }
#inspector .srcItem img { width: 84px; height: 64px; object-fit: cover; border: 2px solid var(--ink); image-rendering: auto; }
#inspector .srcItem .noimg { width: 84px; height: 64px; border: 2px dashed rgba(59,48,42,.4); display: grid; place-items: center; font-size: 10px; opacity: .6; }
#inspector .srcItem small { display: block; opacity: 0.75; font-size: 11px; }
#inspector .conf { display: inline-block; padding: 0 6px; border: 1px solid var(--ink); font-size: 11px; margin-left: 4px; }
#inspector ul { padding-left: 18px; margin: 4px 0; }

@media (max-width: 640px) {
  #hud { top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); right: calc(max(12px, env(safe-area-inset-right)) + 148px); align-items: flex-start; }
  .brand { min-width: 0; }
  #views { flex-wrap: wrap; }
  .logo { font-size: 18px; }
  .place { font-size: 10px; max-width: 210px; }
  .clock { top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); font-size: 12px; padding: 6px; gap: 4px; }
  #controls { left: max(10px, env(safe-area-inset-left)); right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); transform: none; max-width: none; gap: 6px; padding: 8px; }
  #controls button { min-height: 44px; min-width: 44px; padding: 4px 8px; }
  #controls select { min-height: 44px; min-width: 0; max-width: 150px; font-size: 16px; }
  #controls .sep { display: none; }
  #time { flex: 1 1 100%; width: 100%; min-height: 32px; order: 1; margin: 0; }
  #vol { display: none; }
  #hint { top: calc(max(12px, env(safe-area-inset-top)) + 120px); max-width: calc(100vw - 24px); font-size: 10px; white-space: normal; text-align: center; }
  .desktop-hint { display: none; }
  .touch-hint { display: inline; }
  #log { top: auto; bottom: calc(var(--controls-height) + max(10px, env(safe-area-inset-bottom)) + 14px); right: 12px; max-width: calc(100vw - 24px); }
  #log li:nth-child(n+3) { display: none; }
  #inspector { top: auto; left: 12px; right: 12px; width: auto; bottom: calc(var(--controls-height) + max(10px, env(safe-area-inset-bottom)) + 14px); max-height: calc(100dvh - var(--controls-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 100px); overflow-wrap: anywhere; }
  #closeInspector { width: 44px; height: 44px; }
}
@media (pointer: coarse) {
  .desktop-hint { display: none; }
  .touch-hint { display: inline; }
  #controls button, #controls select { min-height: 44px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  #hud { top: max(8px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); }
  #controls { bottom: max(8px, env(safe-area-inset-bottom)); width: calc(100% - 32px); max-width: calc(100% - 32px); }
  #hint, #log { display: none; }
  #inspector { top: 64px; bottom: calc(var(--controls-height) + 20px); max-height: none; }
}
