/* Click-o-Mania '98. A fake late-90s desktop in the studio's blocky style:
   square corners, 3px black outlines, hard offset shadows, Rubik type.
   --T (tile size in px) is set by main.js so the UI scales with the board. */
:root {
  --T: 40px;
  --paper: #FAF7F0;
  --beige: #EFE7D3;
  --slate: #4C5966;
  --slate-dark: #2C343D;
  --ink: #1E2328;
  --slime: #22AA3A;
  --sky: #3DA5F4;
  --sunny: #FFC845;
  --coral: #FF6B57;
  --teal: #1F6F6C;
  --font: "Rubik", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--teal);
  color: var(--ink);
  font: 400 16px/1.35 var(--font);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
button { font: inherit; color: inherit; }
kbd { font: 500 0.85em var(--font); padding: 0 4px; border: 2px solid #000; background: var(--paper); }

/* ---------- Desktop ---------- */
.desktop {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--teal);
}
.desk-icons {
  position: absolute;
  left: 12px;
  top: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.desk-icons[hidden] { display: none; }
.desk-icons li { width: 96px; text-align: center; color: #fff; font: 500 13px/1.2 var(--font); text-shadow: 1px 1px 0 #000; }
.desk-icons canvas { display: block; margin: 0 auto 4px; image-rendering: pixelated; }

/* ---------- Windows ---------- */
.win {
  background: var(--beige);
  border: 3px solid #000;
  box-shadow: 5px 5px 0 #000;
}
.win-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 2px 3px 2px 8px;
  background: var(--slate);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  border-bottom: 3px solid #000;
}
.win-title > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-icon { width: 18px; height: 18px; image-rendering: pixelated; flex: none; }
.win-x {
  flex: none;
  min-width: 30px;
  height: 26px;
  padding: 0 6px;
  border: 2px solid #000;
  background: var(--beige);
  color: #000;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}
.win-x:active { transform: translate(1px, 1px); }

.game-win { position: relative; z-index: 1; }
.hud {
  display: flex;
  gap: 6px;
  padding: 6px;
  border-bottom: 3px solid #000;
  container-type: inline-size;
}
.hud-item {
  flex: 1 1 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  padding: 3px 8px;
  background: var(--paper);
  border: 2px solid #000;
  min-width: 0;
}
.hud .label { font-size: 12px; font-weight: 500; color: #4A4F55; }
.hud .val { font-weight: 800; font-size: clamp(14px, calc(var(--T) * 0.42), 20px); font-variant-numeric: tabular-nums;
  min-width: 0; overflow: hidden; text-overflow: clip; white-space: nowrap; }
/* Score and best get the most room; combo the least. */
.hud-item:nth-child(1), .hud-item:nth-child(3) { flex-grow: 1.4; }
.hud-item:nth-child(2) { flex-grow: 0.7; }
/* Narrow windows (phones): label on top, number underneath, so big scores fit. */
@container (max-width: 440px) {
  .hud-item { flex-direction: column; align-items: flex-start; gap: 0; padding: 2px 7px; }
  .hud .label { font-size: 11px; line-height: 1.2; }
  .hud .val { line-height: 1.15; max-width: 100%; }
}
#combo.hot { color: #B23A2A; }

.board-wrap { position: relative; line-height: 0; }
#board { display: block; touch-action: none; cursor: pointer; }
.board-wrap.frozen #board { cursor: wait; }
.hourglass {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: calc(var(--T) * 1.2);
  line-height: 1;
  display: none;
  pointer-events: none;
  filter: drop-shadow(3px 3px 0 #000);
}
.board-wrap.frozen .hourglass { display: block; }
.board-wrap.glitching { animation: glitch 0.5s steps(5) 1; }
@keyframes glitch {
  0% { transform: translate(0, 0); filter: none; }
  20% { transform: translate(-6px, 2px); filter: hue-rotate(90deg) contrast(1.6); }
  40% { transform: translate(5px, -3px); filter: invert(1); }
  60% { transform: translate(-3px, 0); filter: hue-rotate(200deg); }
  80% { transform: translate(2px, 1px); filter: grayscale(1); }
  100% { transform: translate(0, 0); filter: none; }
}

.statusbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 3px 8px;
  min-height: 28px;
  border-top: 3px solid #000;
  font-size: 13px;
}
.status { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status.flash { font-weight: 700; }
.next { display: flex; align-items: center; gap: 6px; flex: none; }
.next .label { font-size: 12px; color: #4A4F55; }
.next-bar { width: 56px; height: 12px; border: 2px solid #000; background: var(--paper); display: block; }
#next-fill { display: block; height: 100%; width: 0; background: var(--slate); }

/* ---------- Distractions (inside the board) ---------- */
.dx { position: absolute; z-index: 5; line-height: 1.3; }
.popup {
  width: min(calc(var(--T) * 6.4), 92%);
  animation: popin 0.14s steps(3) 1;
}
.popup.small { width: min(calc(var(--T) * 5), 80%); }
.popup.storm .win-title { background: #B23A2A; }
.popup.dial { width: min(calc(var(--T) * 7), 96%); }
@keyframes popin { from { transform: scale(0.6); } to { transform: scale(1); } }
.win-body { display: flex; gap: 10px; align-items: flex-start; padding: 10px 10px 4px; }
.win-body p { margin: 0; font-size: clamp(13px, calc(var(--T) * 0.34), 16px); font-weight: 500; }
.pop-icon { flex: none; width: 36px; height: 36px; image-rendering: pixelated; background: var(--sunny); border: 2px solid #000; padding: 2px; }
.win-buttons { display: flex; gap: 8px; justify-content: flex-end; padding: 8px 10px 10px; }
.btn98 {
  min-height: 40px;
  min-width: 64px;
  padding: 6px 12px;
  border: 3px solid #000;
  background: var(--paper);
  box-shadow: 3px 3px 0 #000;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.btn98:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #000; }
.btn98:disabled { opacity: 0.7; cursor: wait; }

.clip {
  right: 4px;
  bottom: 4px;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  max-width: 92%;
}
.clip-art { image-rendering: pixelated; flex: none; padding: 4px 2px; background: #FFF8C8; border: 3px solid #000; box-shadow: 3px 3px 0 #000; }
.clip-bubble {
  position: relative;
  max-width: calc(var(--T) * 4.6);
  margin-bottom: calc(var(--T) * 1.2);
  padding: 8px;
  background: #FFF8C8;
  border: 3px solid #000;
  box-shadow: 3px 3px 0 #000;
}
.clip-bubble p { margin: 0 0 8px; font-size: clamp(12px, calc(var(--T) * 0.32), 15px); font-weight: 500; }
.clip-bubble .btn98 { width: 100%; font-size: 13px; min-height: 36px; padding: 4px 6px; }

.toolbar {
  left: 0;
  right: 0;
  top: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  align-content: center;
  gap: 4px 8px;
  padding: 2px 6px;
  overflow: hidden;
  background: var(--sky);
  border-bottom: 3px solid #000;
  transition: height 0.4s steps(4);
}
.tb-name { font-weight: 800; font-size: 13px; white-space: nowrap; }
.tb-field { flex: 1; min-width: 80px; padding: 2px 6px; background: #fff; border: 2px solid #000; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: none; }
.toolbar.tall .tb-field { display: block; }
.tb-x { margin-left: auto; min-height: 30px; padding: 2px 8px; font-size: 13px; box-shadow: 2px 2px 0 #000; }

.saver { position: fixed; inset: 0; z-index: 50; width: 100%; height: 100%; cursor: none; touch-action: none; }

/* ---------- Dialogs (start, pause, 5 PM, report) ---------- */
.scrim {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(20, 30, 35, 0.35);
}
.scrim[hidden] { display: none; }
.dialog { width: min(440px, 100%); max-height: 100%; overflow: auto; }
.dialog-body { padding: 14px 16px 16px; }
.dialog-body p { margin: 0 0 10px; }
.dialog .win-title { font-size: 17px; font-weight: 800; }
.lead { font-size: 17px; }
.keys { font-size: 13px; color: #4A4F55; }
@media (pointer: coarse) { .keys { display: none; } }
.best-line { font-weight: 700; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; padding: 0; list-style: none; }
.legend li { display: flex; align-items: center; gap: 6px; padding: 3px 8px 3px 3px; background: var(--paper); border: 2px solid #000; font-size: 13px; font-weight: 500; }
.legend canvas { width: 26px; height: 26px; image-rendering: pixelated; border: 2px solid #000; }
.dialog-buttons { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.btn {
  min-height: 46px;
  padding: 10px 18px;
  border: 3px solid #000;
  background: var(--paper);
  box-shadow: 5px 5px 0 #000;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
}
.btn.primary { background: var(--sky); }
.btn:hover { transform: translate(-1px, -1px); box-shadow: 6px 6px 0 #000; }
.btn:active { transform: translate(3px, 3px); box-shadow: 2px 2px 0 #000; }
.btn:focus-visible, .btn98:focus-visible, .win-x:focus-visible, .begin:focus-visible, .mute:focus-visible { outline: 3px solid var(--sunny); outline-offset: 2px; }
.big-score { font-size: 40px; font-weight: 800; margin: 0 0 8px; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tag { font-size: 14px; font-weight: 700; padding: 4px 10px; background: var(--slime); border: 3px solid #000; box-shadow: 3px 3px 0 #000; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; font-size: 15px; }
.facts dt { color: #4A4F55; }
.facts dd { margin: 0; font-weight: 700; }

/* ---------- Taskbar ---------- */
.taskbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  height: calc(46px + env(safe-area-inset-bottom, 0px));
  padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px));
  background: var(--beige);
  border-top: 3px solid #000;
  z-index: 30;
}
.begin {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px 0 8px;
  border: 3px solid #000;
  background: var(--slime);
  box-shadow: 2px 2px 0 #000;
  font-weight: 800;
  cursor: pointer;
}
.begin canvas { width: 18px; height: 18px; image-rendering: pixelated; }
.begin:active { transform: translate(2px, 2px); box-shadow: none; }
.task {
  flex: 0 1 220px;
  min-width: 0;
  height: 34px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  border: 2px solid #000;
  background: var(--paper);
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tray {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 34px;
  padding: 0 8px 0 2px;
  border: 2px solid #000;
  background: var(--paper);
}
.mute { border: 0; background: none; font-size: 18px; width: 34px; height: 30px; cursor: pointer; padding: 0; }
.clock { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; min-width: 72px; text-align: right; }
@media (max-width: 380px) { .task { display: none; } }

/* ---------- Crash screen ---------- */
.crash {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--slate);
  color: var(--paper);
  font: 500 clamp(15px, 2.4vw, 20px)/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace;
  cursor: pointer;
}
.crash[hidden] { display: none; }
.crash-inner { max-width: 640px; }
.crash-title { display: table; margin: 0 auto 1.4em; padding: 0 10px; background: var(--paper); color: var(--slate); font-weight: 700; }
.crash-press { margin-top: 1.6em; text-align: center; }
.blink { animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .board-wrap.glitching { animation: none; }
  .popup { animation: none; }
}
