/* Retro desktop look: grey bevelled panels, red LED counters, navy title bars. */
:root {
  --face: #c0c0c0;
  --hi: #ffffff;
  --lo: #808080;
  --dk: #404040;
  --desk: #2e6f73;
  --navy: #000080;
  --navy2: #1084d0;
  --text: #000;
  --muted: #555;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--desk);
  color: var(--text);
  font: 13px/1.35 "Segoe UI", Tahoma, Verdana, sans-serif;
}

.raised { border: 2px solid; border-color: var(--hi) var(--lo) var(--lo) var(--hi); }
.sunken { border: 2px solid; border-color: var(--lo) var(--hi) var(--hi) var(--lo); }

.window {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--face);
  border: 2px solid;
  border-color: var(--hi) var(--dk) var(--dk) var(--hi);
}

.titlebar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  background: linear-gradient(90deg, var(--navy), var(--navy2));
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.2px;
  user-select: none;
}
.title-icon { color: #ffd400; font-size: 15px; }
.title-sub { font-weight: 400; opacity: 0.85; }
.look-switch { margin-left: auto; display: flex; }
.look-switch a {
  padding: 1px 10px;
  font-size: 12px;
  font-weight: 400;
  color: #000;
  text-decoration: none;
  background: var(--face);
  border: 2px solid;
  border-color: var(--hi) var(--dk) var(--dk) var(--hi);
}
.look-switch a[aria-current="page"] {
  font-weight: 700;
  background: #dcdcdc;
  border-color: var(--dk) var(--hi) var(--hi) var(--dk);
  cursor: default;
}
.look-switch a:focus-visible { outline: 1px dotted #000; outline-offset: -4px; }

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 286px;
  grid-template-areas: "settings board instruments";
  gap: 8px;
  padding: 8px;
}

.panel {
  background: var(--face);
  border: 2px solid;
  border-color: var(--hi) var(--lo) var(--lo) var(--hi);
  padding: 8px;
  overflow-y: auto;
  min-height: 0;
}
.settings { grid-area: settings; }
.instruments { grid-area: instruments; }

details { margin-bottom: 8px; }
summary {
  cursor: pointer;
  font-weight: 700;
  padding: 3px 4px;
  background: #b4b4b4;
  border: 1px solid var(--lo);
  user-select: none;
}
details[open] > summary { margin-bottom: 6px; }

fieldset {
  margin: 0 0 8px;
  padding: 6px 8px 8px;
  border: 2px groove #eee;
}
legend { padding: 0 4px; }

select {
  width: 100%;
  font: inherit;
  padding: 2px;
  background: #fff;
  border: 2px solid;
  border-color: var(--lo) var(--hi) var(--hi) var(--lo);
}

label.radio, label.check { display: block; padding: 1px 0; cursor: pointer; }
.muted { color: var(--muted); }
.hint { margin: 6px 0 0; font-size: 11.5px; color: var(--muted); }

.buttons { display: flex; gap: 6px; margin-bottom: 6px; }
.btn {
  flex: 1;
  font: inherit;
  padding: 4px 8px;
  background: var(--face);
  border: 2px solid;
  border-color: var(--hi) var(--dk) var(--dk) var(--hi);
  box-shadow: inset -1px -1px 0 var(--lo), inset 1px 1px 0 #dfdfdf;
  cursor: pointer;
}
.btn:active:not(:disabled) { border-color: var(--dk) var(--hi) var(--hi) var(--dk); box-shadow: inset 1px 1px 0 var(--lo); }
.btn:disabled { color: #8a8a8a; text-shadow: 1px 1px 0 #fff; cursor: default; }
.btn:focus-visible { outline: 1px dotted #000; outline-offset: -5px; }

.best { margin: 4px 0 0; }
.help { margin: 4px 0; padding-left: 18px; font-size: 12.5px; }
p.help { padding-left: 0; }
.help li { margin-bottom: 4px; }
kbd {
  display: inline-block;
  min-width: 16px;
  padding: 0 3px;
  margin: 0 1px;
  font: 11px Consolas, monospace;
  text-align: center;
  background: #e8e8e8;
  border: 1px solid var(--lo);
  border-bottom-width: 2px;
}

/* ---- Board ---- */
.board {
  grid-area: board;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.board-frame {
  display: inline-flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
  background: var(--face);
  border-width: 3px;
}
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px;
}
.led {
  min-width: 58px;
  padding: 1px 4px;
  background: #000;
  color: #ff2a1a;
  font: 700 28px/1 Consolas, "Courier New", monospace;
  letter-spacing: 2px;
  text-align: right;
  text-shadow: 0 0 6px rgba(255, 30, 0, 0.7);
  border: 1px solid;
  border-color: var(--lo) var(--hi) var(--hi) var(--lo);
}
.led.blink { animation: blink 0.8s steps(1) infinite; }
@keyframes blink { 50% { color: #5a0000; text-shadow: none; } }

.counter { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.led-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #333;
}
.btn.newgame { flex: 0 0 auto; padding: 6px 14px; font-weight: 700; align-self: flex-end; }

.canvas-wrap {
  position: relative;
  line-height: 0;
  border-width: 3px;
  background: #777;
}
#gridCanvas { display: block; touch-action: none; cursor: crosshair; }

.overlay { position: absolute; inset: 0; pointer-events: none; display: flex; justify-content: center; line-height: 1.4; }
.overlay.hidden { display: none; }
.overlay.ready { align-items: flex-start; padding-top: 12px; }
.overlay.paused { align-items: center; background: rgba(60, 60, 60, 0.92); }
.ov-box {
  max-width: 92%;
  padding: 8px 14px;
  background: rgba(255, 255, 225, 0.93);
  border: 1px solid #000;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.35);
  font-size: 13px;
  text-align: center;
}
.ov-box b { font-size: 14px; }

.status-line { margin: 6px 0 0; min-height: 1.4em; text-align: center; color: #222; }

/* ---- Instruments ---- */
.gauge { line-height: 0; background: #e9e1c4; display: flex; justify-content: center; }
#gaugeCanvas { display: block; max-width: 100%; }

.lcd {
  margin-top: 6px;
  padding: 4px 8px;
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 6px;
  background: linear-gradient(#a7b994, #93a87f);
  color: #18240f;
}
.lcd-value { font: 700 30px/1.05 Consolas, "Courier New", monospace; letter-spacing: 1px; }
.lcd-unit { font-size: 11px; font-weight: 600; }

.trend-row { margin: 6px 0 0; }
.trend { font-weight: 700; }
.trend.up { color: #b3261e; }
.trend.down { color: #1f5fbf; }

.life-row { display: flex; align-items: center; gap: 6px; }
.life-row b { min-width: 38px; text-align: right; }
.life-bar { flex: 1; height: 22px; background: #2b2b2b; position: relative; }
.life-fill { height: 100%; transition: background-color 0.4s; }
.life-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 9px, rgba(0, 0, 0, 0.35) 9px 11px);
}
.life-fill.ok { background: linear-gradient(#5fe36b, #1f9e2c); }
.life-fill.warn { background: linear-gradient(#ffe066, #e0a800); }
.life-fill.danger { background: linear-gradient(#ff7b6b, #c62828); animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse { 50% { filter: brightness(1.35); } }

table.readings { width: 100%; margin-top: 8px; border-collapse: collapse; }
table.readings th { text-align: left; font-weight: 400; padding: 2px 0; }
table.readings td { text-align: right; font-family: Consolas, "Courier New", monospace; font-weight: 700; }

/* ---- Result dialog ---- */
.dialog {
  padding: 0;
  min-width: min(420px, 94vw);
  background: var(--face);
  border: 2px solid;
  border-color: var(--hi) var(--dk) var(--dk) var(--hi);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.4);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.dialog-body { padding: 12px 14px 4px; }
.dialog-buttons { display: flex; gap: 8px; justify-content: flex-end; padding: 8px 14px 12px; }
.dialog-buttons .btn { flex: 0 0 auto; min-width: 96px; }
table.stats { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
table.stats th { text-align: left; font-weight: 400; padding: 3px 8px 3px 0; white-space: nowrap; }
table.stats td { padding: 3px 0; }
table.stats.score { background: #fff; border: 2px solid; border-color: var(--lo) var(--hi) var(--hi) var(--lo); }
table.stats.score th, table.stats.score td { padding: 3px 8px; }
table.stats.score td:last-child { text-align: right; font-family: Consolas, monospace; font-weight: 700; }
table.stats.score tr.total { border-top: 1px solid var(--lo); font-weight: 700; font-size: 15px; }
.newbest { color: #a05a00; font-weight: 700; margin: 0 0 6px; }

/* ---- Responsive ---- */
@media (max-width: 1180px) {
  .layout {
    grid-template-columns: 250px minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas: "instruments board" "settings board";
    overflow-y: auto;
  }
  .panel { overflow: visible; }
}

@media (max-width: 820px) {
  .window { height: auto; min-height: 100vh; }
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    grid-template-areas: "settings" "board" "instruments";
    padding: 6px;
  }
  .settings details:first-child:not([open]) { margin-bottom: 0; }
  .title-sub { display: none; }
  .led { font-size: 22px; min-width: 48px; }
}
