.win {
  background: #c0c0c0;
  border: 2px solid;
  border-color: #ffffff #000000 #000000 #ffffff;
  box-shadow: inset 1px 1px 0 #dfdfdf, inset -1px -1px 0 #808080;
  /* Auto-size to fit the grid exactly — no blank right margin. */
  width: fit-content;
  user-select: none;
}
.win__titlebar {
  background: linear-gradient(90deg, #000080 0%, #1084d0 100%);
  color: #fff;
  padding: 2px 3px 3px 3px;
  display: flex;
  align-items: center;
  font-weight: bold;
  font-size: 11px;
}
.win__icon {
  width: 16px; height: 16px;
  background: url('../assets/defrag-icon.webp') center/contain no-repeat;
  margin-right: 4px;
  image-rendering: pixelated;
}
.win__title { flex: 1; padding-left: 2px; }
.win__btn {
  width: 16px; height: 14px;
  background: #c0c0c0;
  border: 1px solid;
  border-color: #fff #000 #000 #fff;
  box-shadow: inset 1px 1px 0 #dfdfdf, inset -1px -1px 0 #808080;
  margin-left: 2px;
  font-size: 9px;
  line-height: 11px;
  text-align: center;
  color: #000;
  font-weight: bold;
}
.win__menubar {
  padding: 2px 4px;
  border-bottom: 1px solid #808080;
  box-shadow: 0 1px 0 #fff;
}
.win__menubar span { padding: 1px 6px; }
.win__menubar u { text-decoration: underline; }
.win__body { padding: 6px; }
.display-frame {
  background: #fff;
  border: 2px solid;
  border-color: #808080 #fff #fff #808080;
  padding: 4px;
  overflow: hidden;
}
.statusrow {
  display: grid;
  grid-template-columns: 1fr auto auto;
  grid-template-rows: auto auto auto;
  gap: 4px 8px;
  margin-top: 8px;
  align-items: center;
}
.statusrow__text { grid-column: 1; grid-row: 1; font-size: 11px; }
.statusrow__progress {
  grid-column: 1; grid-row: 2;
  height: 14px;
  background: #fff;
  border: 2px solid;
  border-color: #808080 #fff #fff #808080;
  padding: 1px;
  overflow: hidden;
}
.statusrow__progress > div {
  height: 100%; width: 0%;
  background: repeating-linear-gradient(90deg, #000080 0 8px, #fff 8px 9px);
  transition: width 0.1s linear;
}
.statusrow__pct { grid-column: 1; grid-row: 3; font-size: 11px; }
.statusrow__btns {
  grid-column: 2 / 4; grid-row: 1 / 4;
  display: grid;
  grid-template-columns: auto auto;
  gap: 4px;
  align-self: start;
}
.btn {
  background: #c0c0c0;
  border: 2px solid;
  border-color: #fff #000 #000 #fff;
  box-shadow: inset 1px 1px 0 #dfdfdf, inset -1px -1px 0 #808080;
  padding: 3px 14px;
  font-family: inherit;
  font-size: 11px;
  min-width: 64px;
}
.btn u { text-decoration: underline; }
/* Pressed state — inverted bevel */
.btn:active {
  border-color: #000 #fff #fff #000;
  box-shadow: inset 1px 1px 0 #808080, inset -1px -1px 0 #dfdfdf;
  padding: 4px 13px 2px 15px;
}
/* Win98 dotted-rect focus marker, drawn inside the button */
.btn:focus {
  outline: 1px dotted #000;
  outline-offset: -4px;
}
.btn::-moz-focus-inner { border: 0; padding: 0; }

/* Legend modal */
.legend-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.legend-modal[hidden] { display: none; }
.legend-modal__bg {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}
.legend-modal__win {
  position: relative;
  width: 460px;
  max-height: 80vh;
  overflow: hidden;
}
.legend-modal__body {
  padding: 12px;
  max-height: calc(80vh - 26px);
  overflow-y: auto;
  font-size: 11px;
  line-height: 1.4;
}
.legend-modal__body h3 {
  margin: 8px 0 4px 0;
  font-size: 11px;
  border-bottom: 1px solid #808080;
  padding-bottom: 2px;
}
.legend-modal__body h3:first-child { margin-top: 0; }
.legend-modal__body p { margin: 0 0 8px 0; }
.legend-modal__body ul { margin: 4px 0 8px 18px; padding: 0; }
.legend-modal__body li { margin-bottom: 2px; }
.legend-modal__body table.legend-blocks {
  width: 100%;
  border-collapse: collapse;
}
.legend-modal__body table.legend-blocks td {
  padding: 1px 4px;
  vertical-align: middle;
}
.legend-modal__body table.legend-blocks td:first-child { width: 18px; }
.legend-modal__body table.legend-blocks td.legend-subhead {
  padding-top: 6px;
  font-weight: bold;
}
/* Indent the entire sub-item row (swatch + label) under "Unoptimized data that:" */
.legend-modal__body table.legend-blocks tr.legend-row-sub td:first-child { padding-left: 16px; }
.legend-modal__body table.legend-blocks tr.legend-row-sub td:first-child { width: 30px; }
.legend-swatch {
  display: inline-block;
  width: 10px;
  height: 14px;
  border: 1px solid #000;
  vertical-align: middle;
  margin-right: 3px;
  image-rendering: pixelated;
}
.swatch--cyan-solid { background: #00b0b0; border-color: #006666; }
.swatch--cyan-diag {
  background: repeating-linear-gradient(-45deg, #00d8d8 0 2px, #006666 2px 3px);
  border-color: #004444;
}
.swatch--cyan-dots {
  background: radial-gradient(#004444 0.6px, transparent 0.7px) 0 0 / 3px 3px, #00b0b0;
  border-color: #004444;
}
.swatch--opt { background: #0000a8; border-color: #000044; }
.swatch--free { background: #fff; border-color: #c0c0c0; }
.swatch--sys {
  background: repeating-linear-gradient(-45deg, #404040 0 2px, #606060 2px 3px);
  border-color: #000;
}
.swatch--bad {
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 14' preserveAspectRatio='none'><line x1='0' y1='0' x2='10' y2='14' stroke='%23d80000' stroke-width='1.4'/></svg>") no-repeat center / 100% 100%,
    #fff;
  border-color: #000;
}
.swatch--checkpoint {
  background: radial-gradient(#fff 0.8px, transparent 1px) 0 0 / 3px 3px, #008000;
  border-color: #004000;
}
.swatch--fragile {
  background: repeating-linear-gradient(90deg, #c0a000 0 2px, #604000 2px 3px);
  border-color: #402000;
}
.swatch--goal {
  background: repeating-linear-gradient(45deg, #ff00ff 0 2px, #800080 2px 3px);
  border-color: #400040;
}
.swatch--coin {
  background: linear-gradient(135deg, #fff4a3, #d4af37 55%, #8b6914);
  border-color: #6b4c00;
}
.swatch--read { background: #00c000; border-color: #006600; }
.swatch--write { background: #ff4040; border-color: #800000; }
.swatch--player { background: #ffff00; border-color: #806000; }
.legend-foot {
  margin-top: 8px;
  padding-top: 4px;
  border-top: 1px solid #808080;
  font-size: 11px;
  color: #404040;
}
