@font-face {
  font-family: "PixelOperator";
  src: url("assets/fonts/PixelOperator.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "PixelOperator";
  src: url("assets/fonts/PixelOperator-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #F7F7F5;
  --ink: #111111;
  --u: 2px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  border-radius: 0;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100svh;
  background: var(--paper);
  color: var(--ink);
  font-family: "PixelOperator", ui-monospace, Menlo, monospace;
  font-size: 20px;
  line-height: 1;
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: grayscale;
  font-smooth: never;
  overflow-x: hidden;
}

img,
canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

button,
a {
  font-family: inherit;
  color: inherit;
}

button:focus,
a:focus {
  outline: none;
}

button:focus-visible,
a:focus-visible {
  outline: 2px dotted var(--ink);
  outline-offset: -2px;
}

/* Subtle CRT overlay matching Shaders/CrtScreen.shader (scanlines + soft vignette). */
.crt-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 90;
  background-image:
    repeating-linear-gradient(
      to bottom,
      rgba(17, 17, 17, 0.08) 0 1px,
      transparent 1px 2px
    ),
    radial-gradient(
      circle at 50% 45%,
      transparent 55%,
      rgba(17, 17, 17, 0.14) 100%
    );
}

body.crt-off .crt-overlay {
  display: none;
}

.zoom-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 80;
}

.zoom-rect {
  position: fixed;
  border: 2px solid var(--ink);
  mix-blend-mode: difference;
  pointer-events: none;
}

.desktop {
  position: relative;
  min-height: 100svh;
  width: 100%;
  padding: 16px 12px 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Top-right CRT/Settings corner control */
.desktop-tool {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 4px;
  background: var(--paper);
  border: 4px solid var(--ink);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
}

.desktop-tool:active,
.desktop-tool.is-active {
  background: var(--ink);
  color: var(--paper);
}

.desktop-tool canvas {
  width: 24px;
  height: 24px;
}

/* Desktop app icon */
.desktop-icon {
  position: fixed;
  top: 28px;
  left: 28px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 4px;
  border: 0;
  background: transparent;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.desktop-icon img {
  width: 64px;
  height: 64px;
  padding: 2px;
  background: transparent;
}

.desktop-icon-label {
  display: inline-block;
  padding: 4px 6px;
  background: var(--paper);
  color: var(--ink);
  font-size: 18px;
  font-weight: 400;
  white-space: nowrap;
}

.desktop-icon.is-selected img {
  background: var(--ink);
  filter: invert(1);
}

.desktop-icon.is-selected .desktop-icon-label {
  background: var(--ink);
  color: var(--paper);
}

body.window-closed .desktop-icon {
  position: static;
  margin-bottom: 16px;
}

/* Classic 1-bit WindowFrame (border 2u, inset 2u, solid title bar) */
.win {
  position: relative;
  z-index: 10;
  width: 342px;
  max-width: calc(100vw - 16px);
  background: var(--paper);
  border: 4px solid var(--ink);
  padding: 4px;
  user-select: none;
  -webkit-user-select: none;
}

.win[hidden] {
  display: none;
}

.win-inner {
  display: flex;
  flex-direction: column;
}

.win-titlebar {
  height: 32px;
  background: var(--ink);
  color: var(--paper);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px 0 6px;
  cursor: grab;
  touch-action: none;
}

.win-titlebar:active {
  cursor: grabbing;
}

.chrome-sprite {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
}

.win-title {
  flex: 1;
  text-align: left;
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
}

.win-floating .win-titlebar {
  padding-left: 8px;
}

.win-floating .win-title {
  text-align: center;
}

.close-btn {
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
}

.close-btn:active {
  filter: invert(1);
}

.win-titlebar .close-btn:focus-visible,
.mini-dialog-titlebar .close-btn:focus-visible {
  outline: 2px dotted var(--paper);
}

/* Menu bar */
.menubar {
  height: 32px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
}

.menu-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.menu-item {
  border: 0;
  background: transparent;
  padding: 2px 4px;
  font-size: 20px;
  line-height: 1;
  font-weight: 400;
  cursor: pointer;
}

.menu-item u {
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}

.menu-item:active,
.menu-item[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

.menu-level {
  font-size: 20px;
  font-weight: 400;
}

.sep {
  height: 4px;
  background: var(--ink);
  margin: 0 -4px;
}

/* HUD */
.hud {
  height: 82px;
  padding: 8px 8px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hud-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hud-right {
  align-items: flex-end;
}

.hud-label {
  font-size: 18px;
  font-weight: 400;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.lcd-canvas {
  width: 106px;
  height: 38px;
}

.face-btn {
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
}

.face-canvas {
  width: 64px;
  height: 64px;
}

/* Board field */
.field-wrap {
  padding: 8px 4px 4px;
  display: flex;
  justify-content: center;
}

.field-frame {
  position: relative;
  border: 4px solid var(--ink);
  background: var(--paper);
  width: 100%;
  max-width: 318px;
  aspect-ratio: 1 / 1;
}

#field-canvas {
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: manipulation;
}

/* Small win/lose dialog inside the dithered field */
.mini-dialog {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 224px;
  background: var(--paper);
  border: 4px solid var(--ink);
  padding: 4px;
  z-index: 4;
}

.mini-dialog[hidden] {
  display: none;
}

.mini-dialog-inner {
  display: flex;
  flex-direction: column;
}

.mini-dialog-titlebar {
  height: 30px;
  background: var(--ink);
  color: var(--paper);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 0 8px;
  font-size: 20px;
}

.mini-dialog-body {
  padding: 12px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* About dialog */
.win-floating {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 272px;
  z-index: 40;
}

.about-body {
  padding: 12px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.about-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 6px;
  border-bottom: 2px dotted var(--ink);
}

.about-head img {
  width: 48px;
  height: 48px;
}

.about-name {
  font-size: 22px;
  font-weight: 700;
}

.about-meta {
  font-size: 18px;
  margin-top: 4px;
}

.about-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.px-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 38px;
  background: var(--paper);
  color: var(--ink);
  border: 4px solid var(--ink);
  font-size: 20px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.px-btn:hover,
.px-btn:active {
  background: var(--ink);
  color: var(--paper);
}

/* Desktop footer */
.desktop-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 42px;
  padding: 0 16px;
  background: var(--paper);
  border-top: 2px solid var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 18px;
  z-index: 15;
}

.footer-brand {
  letter-spacing: 1px;
  white-space: nowrap;
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.footer-links a {
  text-decoration: none;
  border-bottom: 2px solid transparent;
}

.footer-links a:hover {
  border-bottom-color: var(--ink);
}

@media (max-width: 680px) {
  .desktop-icon {
    position: static;
    margin-bottom: 12px;
  }

  .desktop-tool {
    top: 8px;
    right: 8px;
  }

  .desktop {
    padding-top: 52px;
    justify-content: flex-start;
  }

  .desktop-footer {
    justify-content: center;
  }

  .footer-brand {
    display: none;
  }
}

@media (max-width: 368px) {
  .win {
    width: 100%;
  }

  .lcd-canvas {
    width: 88px;
    height: 32px;
  }

  .face-btn,
  .face-canvas {
    width: 56px;
    height: 56px;
  }
}
