/* Boxes - web port. Classic Win9x styling to match the original. */
:root {
  --face: #c0c0c0;
  --shadow: #808080;
  --dark: #404040;
  --light: #ffffff;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  overscroll-behavior: none;   /* no pull-to-refresh / bounce on mobile */
}
body {
  background: #008080; /* classic teal desktop */
  font-family: "Tahoma", "MS Sans Serif", "Segoe UI", sans-serif;
  font-size: 13px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 8px 40px;
  color: #000;
}

#app {
  background: var(--face);
  border: 2px solid;
  border-color: var(--light) var(--dark) var(--dark) var(--light);
  box-shadow: 1px 1px 0 var(--shadow), 4px 4px 12px rgba(0,0,0,.4);
  width: min(100%, 600px);
  max-width: 100%;
}

/* Title bar */
#titlebar {
  background: linear-gradient(#000080, #1084d0);
  color: #fff;
  font-weight: bold;
  padding: 3px 4px;
  display: flex;
  align-items: center;
  gap: 5px;
  user-select: none;
}
#titlebar .titleicon { width: 16px; height: 16px; image-rendering: pixelated; }

/* Menu bar */
#menubar {
  display: flex;
  background: var(--face);
  border-bottom: 1px solid var(--shadow);
  padding: 1px 2px;
  user-select: none;
}
.menu { position: relative; }
.menu-title {
  display: inline-block;
  padding: 3px 8px;
  cursor: default;
}
.menu.open .menu-title,
.menu-title:hover { background: #000080; color: #fff; }
.menu-drop {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 190px;
  background: var(--face);
  border: 2px solid;
  border-color: var(--light) var(--dark) var(--dark) var(--light);
  box-shadow: 2px 2px 5px rgba(0,0,0,.4);
  z-index: 20;
  padding: 2px;
}
.menu.open .menu-drop { display: block; }
.menu-item {
  padding: 4px 20px 4px 24px;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  cursor: default;
  white-space: nowrap;
}
.menu-item:hover { background: #000080; color: #fff; }
.menu-item .accel { color: inherit; opacity: .8; }
.menu-sep { height: 1px; background: var(--shadow); border-bottom: 1px solid var(--light); margin: 3px 2px; }

/* Canvas. The board is a fixed 600x440 (landscape) image; it scales with the
   window width on desktop. On a phone the mobile block below switches to a
   flex layout that fits it to the viewport height too (see #board). */
#board { display: contents; }   /* inert wrapper on desktop */
#screen {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #fff;
  outline: none;
  border-top: 1px solid var(--shadow);
  touch-action: none;   /* taps drive the game; no scroll / double-tap zoom */
}

/* Dialogs */
.dialog-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.25);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.dialog-overlay.open { display: flex; }
.dialog {
  background: var(--face);
  border: 2px solid;
  border-color: var(--light) var(--dark) var(--dark) var(--light);
  box-shadow: 3px 3px 10px rgba(0,0,0,.5);
  width: min(92vw, 340px);
}
.dialog-title {
  background: linear-gradient(#000080, #1084d0);
  color: #fff;
  font-weight: bold;
  padding: 3px 6px;
}
.dialog-body {
  padding: 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  line-height: 1.4;
}
.dialog-body p { margin: 0; }
.dialog-icon { width: 32px; height: 32px; image-rendering: pixelated; flex: none; }
.settings-body { flex-direction: column; gap: 8px; }
.settings-body label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.settings-body input {
  width: 90px;
  font-family: inherit;
  font-size: 12px;
  border: 2px solid;
  border-color: var(--shadow) var(--light) var(--light) var(--shadow);
  padding: 2px 4px;
}
.dialog-buttons {
  padding: 4px 16px 16px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.dialog-buttons button {
  font-family: inherit;
  font-size: 12px;
  min-width: 66px;
  padding: 4px 10px;
  background: var(--face);
  border: 2px solid;
  border-color: var(--light) var(--dark) var(--dark) var(--light);
  cursor: pointer;
}
.dialog-buttons button:active {
  border-color: var(--dark) var(--light) var(--light) var(--dark);
}

#hint {
  color: #cfe8e8;
  margin: 14px 0 0;
  text-align: center;
  font-size: 12px;
}

/* Shown only on a portrait touch screen, where a landscape board is cramped. */
#rotatehint {
  display: none;
  color: #eaf6f6;
  margin: 10px 0 0;
  text-align: center;
  font-size: 12px;
  opacity: .85;
}
#rotatehint::before { content: "\21BB\00A0"; }  /* ↻ */
@media (orientation: portrait) and (pointer: coarse) {
  #rotatehint { display: block; }
}

/* ---- mobile / touch ---------------------------------------------------- */
@media (max-width: 640px), (pointer: coarse) {
  html, body { height: 100%; }
  body {
    /* Fill the screen exactly and never scroll: the board is fit to the
       viewport below, so there is nothing off-screen to reach. */
    height: 100dvh;
    justify-content: center;
    overflow: hidden;
    /* keep clear of notches / rounded corners while staying compact */
    padding:
      max(6px, env(safe-area-inset-top))
      max(6px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(6px, env(safe-area-inset-left));
  }

  /* The window fills the available height; the board sits inside it, scaled to
     the largest size that fits BOTH the width and the remaining height, so the
     whole board is always visible in either orientation. */
  #app {
    width: min(100%, 600px);
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  #titlebar, #menubar { flex: none; }
  #board {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: var(--face);
  }
  /* width/height auto + max 100% = letterbox to fit, aspect ratio preserved */
  #screen {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
  }

  /* bigger tap targets for the Win9x menu and dialog controls */
  .menu-title { padding: 8px 12px; }
  .menu-item { padding: 10px 18px 10px 20px; }
  .dialog { width: min(94vw, 360px); }
  .dialog-buttons button { min-width: 84px; padding: 10px 14px; font-size: 14px; }
  .settings-body input { padding: 6px; font-size: 14px; }

  #hint { font-size: 13px; margin: 8px 0 0; }
  #rotatehint { margin-top: 6px; }
}

/* Landscape phones are short on height, and the board's limiting dimension is
   height there. Trim every bit of vertical chrome so the board grows to fill
   the space: minimal top/bottom padding, slimmer bars, and drop the hint
   (its "arrow keys" tip is desktop-only anyway — on touch you tap the board). */
@media (pointer: coarse) and (orientation: landscape) {
  body {
    padding-top: max(3px, env(safe-area-inset-top));
    padding-bottom: max(3px, env(safe-area-inset-bottom));
  }
  #titlebar { padding: 2px 4px; }
  #titlebar .titleicon { width: 14px; height: 14px; }
  .menu-title { padding: 4px 12px; }
  #hint { display: none; }
}
