:root {
  --bg: #1d1a33; --panel: #2a2650; --panel2: #352f66; --ink: #ecebf7; --muted: #a9a5cc;
  --accent: #b8c76f; --blue: #6c5eb5; --err: #ff8a7a; --warn: #f1d36b;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.4 -apple-system, "Helvetica Neue", Helvetica, Arial, sans-serif; }
header { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: #352879; border-bottom: 4px solid var(--blue); }
header h1 { margin: 0; font-size: 20px; letter-spacing: 1px; text-transform: uppercase; }
header h1 span { color: var(--accent); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
button, .button { background: var(--panel2); color: var(--ink); border: 1px solid #5a52a0; border-radius: 6px; padding: 6px 12px; font: inherit; cursor: pointer; display: inline-block; }
button:hover:not(:disabled), .button:hover { background: #463e86; }
button:disabled, .button.disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: #1d1a33; border-color: var(--accent); font-weight: 600; }
button.on { background: var(--blue); border-color: #9a90e0; }
.button input { display: none; }

#welcome { max-width: 720px; margin: 60px auto; padding: 24px 30px; background: var(--panel); border-radius: 12px; }
#welcome h2 { margin-top: 0; }
#status { margin-top: 14px; color: var(--accent); white-space: pre-line; }
.small { font-size: 12.5px; color: var(--muted); }
code { background: #00000040; padding: 1px 5px; border-radius: 4px; }

#app { display: grid; grid-template-columns: 180px minmax(0, 1fr) 320px; gap: 12px; padding: 12px; height: calc(100vh - 58px); }
#roomList { overflow-y: auto; background: var(--panel); border-radius: 10px; padding: 8px; }
.roomItem { display: block; width: 100%; text-align: left; padding: 5px; margin-bottom: 6px; border-radius: 6px; background: transparent; border: 2px solid transparent; }
.roomItem.on { border-color: var(--accent); background: var(--panel2); }
.roomItem canvas { width: 100%; image-rendering: pixelated; display: block; border-radius: 3px; }
.roomItem .lbl { display: flex; justify-content: space-between; font-size: 12px; margin-top: 3px; }
.roomItem .tag { color: var(--accent); }
.roomItem .dot { color: var(--err); }

#center { display: flex; flex-direction: column; align-items: center; overflow: auto; min-width: 0; }
#roomHeader { width: 100%; max-width: 960px; display: flex; align-items: baseline; gap: 14px; }
#roomHeader h2 { margin: 4px 0 8px; }
#roomNote { color: var(--accent); }
#canvasWrap { position: relative; width: 100%; max-width: 960px; }
#roomCanvas { image-rendering: pixelated; border: 2px solid #5a52a0; border-radius: 4px; cursor: crosshair; display: block; width: 100%; height: auto;
  touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button, .button, .swatch { touch-action: manipulation; }
#hoverInfo { width: 100%; max-width: 960px; color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.row { display: flex; gap: 14px; align-items: center; }
.toggles { width: 100%; max-width: 960px; margin-top: 6px; flex-wrap: wrap; }
.toggles #delBtn { margin-left: auto; }

#side { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.panel { background: var(--panel); border-radius: 10px; padding: 10px 12px; }
.panel h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#furniturePalette[hidden], #app[hidden], #welcome[hidden], #randRooms[hidden], #randPanel[hidden] { display: none; }
/* wording for touch screens and the iPad app (classes set by app.js) */
.only-app, html.touch .no-touch, html.in-app .no-app { display: none; }
html.in-app .only-app { display: inline; }
#furniturePalette { margin-top: 10px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; max-height: 280px; overflow-y: auto; }
.fItem { padding: 4px; background: #00000030; border: 2px solid transparent; border-radius: 6px; text-align: center; font-size: 11px; }
.fItem.on { border-color: var(--accent); }
.fItem canvas { max-width: 100%; image-rendering: pixelated; display: block; margin: 0 auto 2px; }
.field { display: flex; align-items: center; justify-content: space-between; margin: 6px 0; gap: 8px; }
.field > span { color: var(--muted); font-size: 12.5px; }
.swatches { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; max-width: 200px; }
.swatch { width: 26px; height: 22px; border-radius: 4px; border: 2px solid #00000060; cursor: pointer; padding: 0; }
.swatches.small .swatch { width: 18px; height: 16px; }
.swatch.on { border-color: #fff; box-shadow: 0 0 0 1px #000; }
#inspector input[type=number], #inspector input[type=text], #inspector select { width: 110px; background: #1d1a33; color: var(--ink); border: 1px solid #5a52a0; border-radius: 4px; padding: 3px 5px; font: inherit; }
#inspector .note { font-size: 12px; color: var(--muted); margin-top: 6px; }
.muted { color: var(--muted); }
#meter { height: 10px; background: #00000050; border-radius: 5px; overflow: hidden; }
#meterBar { height: 100%; background: var(--accent); width: 0; }
#meterText { font-size: 12px; color: var(--muted); margin: 4px 0 8px; }
#checks .err { color: var(--err); margin: 3px 0; font-size: 12.5px; }
#checks .warn { color: var(--warn); margin: 3px 0; font-size: 12.5px; }
#checks .ok { color: var(--accent); font-size: 12.5px; }
#checks a { color: inherit; cursor: pointer; text-decoration: underline; }
body.dragover::after { content: "Drop the .d64 to load it"; position: fixed; inset: 0; background: #352879d0; display: flex; align-items: center; justify-content: center; font-size: 28px; }

/* ---------- tablets ---------- */
/* landscape tablets (iPad mini is 1133 points wide): slimmer side columns */
@media (max-width: 1200px) {
  #app { grid-template-columns: 130px minmax(0, 1fr) 270px; gap: 8px; padding: 8px; }
  header { padding: 8px 10px; }
  header h1 { font-size: 16px; }
}
/* portrait: one column; rooms become a strip of thumbnails, panels go below the room */
@media (max-width: 900px) {
  header { flex-wrap: wrap; gap: 8px; }
  #app { display: block; height: auto; }
  #roomList { display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden; padding: 6px; margin-bottom: 8px; }
  .roomItem { flex: 0 0 104px; margin-bottom: 0; }
  #side { overflow: visible; margin-top: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: start; }
  #side .panel:first-child { grid-column: 1 / -1; }
  .toolbar { grid-template-columns: repeat(6, 1fr); }
  #furniturePalette { grid-template-columns: repeat(6, 1fr); }
}
/* touch screens: bigger targets */
@media (pointer: coarse) {
  button, .button { padding: 9px 14px; }
  .swatch { width: 32px; height: 28px; }
  .swatches.small .swatch { width: 26px; height: 24px; }
  .swatches { max-width: 240px; }
  .toggles label { padding: 6px 0; }
  .toggles input[type=checkbox] { width: 20px; height: 20px; vertical-align: middle; }
  #inspector input[type=number], #inspector input[type=text], #inspector select { font-size: 16px; padding: 6px; }  /* 16px stops iOS zooming in */
}

/* ---------- randomize panel ---------- */
.seg { display: flex; }
.seg button { border-radius: 0; padding: 4px 8px; font-size: 12.5px; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.checkrow { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; font-size: 12.5px; }
#randRooms { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin: 6px 0; }
.chip { padding: 3px 0; font-size: 12px; text-align: center; }
.chip.on { background: var(--accent); color: #1d1a33; border-color: var(--accent); }
#randSeed { width: 90px; background: #1d1a33; color: var(--ink); border: 1px solid #5a52a0; border-radius: 4px; padding: 3px 5px; font: inherit; }
button.wide { width: 100%; margin-top: 6px; }
#randPanel .note { font-size: 12px; color: var(--muted); margin-top: 6px; }
@media (pointer: coarse) {
  .seg button { padding: 8px 10px; }
  .chip { padding: 8px 0; }
  #randSeed { font-size: 16px; padding: 6px; }
}
