:root {
  --white: #fff;
  --black: #111;
  --line: #111;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  color: var(--black);
  background: var(--white);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
}

button { color: inherit; font: inherit; }
button:focus-visible { outline: 1px dashed var(--black); outline-offset: 3px; }

.topbar {
  position: fixed;
  z-index: 100;
  inset: 0 0 auto;
  height: 72px;
  display: grid;
  grid-template-columns: 1fr 120px;
  border-bottom: 1px solid var(--line);
  background: var(--white);
}

.mode-switcher { display: flex; justify-content: center; }

.mode-button {
  min-width: 170px;
  padding: 10px 18px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--white);
  cursor: pointer;
  text-transform: lowercase;
}

.mode-button:first-child { border-left: 1px solid var(--line); }
.mode-button span { display: block; margin-bottom: 3px; font-family: 'Courier New', monospace; font-size: 9px; }
.mode-button:hover, .mode-button.is-active { color: var(--white); background: var(--black); }

.source-count {
  margin: 0;
  padding: 14px 16px;
  border-left: 1px solid var(--line);
  font-family: 'Courier New', monospace;
  font-size: 9px;
  line-height: 1.45;
  text-align: right;
}

#app { position: fixed; inset: 72px 0 48px; }
.mode-panel { position: absolute; inset: 0; display: none; background: var(--white); }
.mode-panel.is-active { display: block; }

body[data-mode="doors"] #app { bottom: 0; }
body[data-mode="doors"] .detail-strip { display: none; }
body.door-is-open .topbar { display: none; }
body.door-is-open #app { inset: 0; }

.doors-mode {
  overflow: auto;
  padding: clamp(24px, 4vw, 58px);
}

.doors-index h1 {
  max-width: 920px;
  margin: 0 0 clamp(36px, 6vh, 72px);
  font-family: Arial, Helvetica, sans-serif;
  font-size: clamp(30px, 5.2vw, 76px);
  font-weight: 400;
  line-height: .92;
  letter-spacing: -.055em;
}

.doors-grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(54px, 1fr));
  grid-auto-rows: 120px;
  gap: clamp(12px, 2vw, 28px);
  align-items: end;
  padding-bottom: 50px;
}

.door {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--white);
  overflow: hidden;
  text-align: left;
  vertical-align: top;
  cursor: pointer;
}

.door::after {
  content: '';
  position: absolute;
  right: 8px;
  top: 52%;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--black);
}

.door:hover:not(:disabled), .door:focus-visible { color: var(--white); background: var(--black); }
.door:disabled { color: var(--black); cursor: not-allowed; }
.door:disabled::after { background: var(--black); }
.door-status { font-family: 'Courier New', monospace; font-size: 8px; line-height: 1.2; }

.door.is-open { padding: 0; background: var(--white); cursor: pointer; }
.door.is-open::after { display: none; }
.door.is-open img { width: 100%; height: 100%; display: block; object-fit: contain; }

.door:nth-child(1), .door:nth-child(7), .door:nth-child(13) { grid-row: span 2; }
.door:nth-child(4), .door:nth-child(10), .door:nth-child(16) { height: 72%; }
.door:nth-child(5), .door:nth-child(12) { grid-column: span 2; }
.door:nth-child(8), .door:nth-child(17) { height: 48%; }
.door:nth-child(14) { grid-column: span 2; grid-row: span 2; }

.door-room {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: 42px minmax(0, 1fr) 22px;
  place-items: center;
  padding: 18px 24px 20px;
  background: var(--white);
  overflow: auto;
}

.door-room-back {
  justify-self: start;
  align-self: start;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--white);
  font-family: 'Courier New', monospace;
  font-size: 10px;
  cursor: pointer;
}

.door-room-back:hover { color: var(--white); background: var(--black); }

.door-room img {
  display: block;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 104px);
  width: auto;
  height: auto;
  object-fit: contain;
  cursor: zoom-in;
}

.door-room img.is-zoomed {
  max-width: none;
  max-height: none;
  width: min(1600px, 160vw);
  cursor: zoom-out;
}

.door-room p {
  justify-self: end;
  margin: 0;
  font-family: 'Courier New', monospace;
  font-size: 9px;
}

.drawer-mode.is-active {
  display: grid;
  grid-template-columns: minmax(340px, 42vw) 1fr;
  overflow: auto;
}

.cabinet-wrap {
  min-height: 620px;
  padding: 38px;
  display: grid;
  place-items: center;
  border-right: 1px solid var(--line);
}

.cabinet {
  width: min(430px, 100%);
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.drawer {
  position: relative;
  min-height: 58px;
  padding: 12px;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--white);
  text-align: left;
  cursor: pointer;
}

.drawer:hover:not(:disabled), .drawer.is-selected { color: var(--white); background: var(--black); }
.drawer:disabled { color: #777; cursor: not-allowed; }
.drawer-label { font-family: 'Courier New', monospace; font-size: 10px; }
.drawer-lock { float: right; font-size: 11px; }

.drawer-desk {
  position: relative;
  min-height: 620px;
  display: grid;
  place-items: center;
  padding: 36px 46px 60px;
  overflow: hidden;
}

.page-mount { height: min(68vh, 620px); max-width: 94%; border: 1px solid var(--line); background: var(--white); }
.page-mount img { display: block; height: 100%; max-width: 100%; object-fit: contain; }

.desk-caption {
  position: absolute;
  right: 20px;
  bottom: 16px;
  display: grid;
  gap: 2px;
  font-family: 'Courier New', monospace;
  font-size: 9px;
  text-align: right;
}

.wall-mode { background: var(--white); }
.wall-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  background: var(--white);
}
.wall-viewport.is-dragging { cursor: grabbing; }

.wall-canvas {
  position: absolute;
  width: 5300px;
  height: 4500px;
  transform-origin: 0 0;
  will-change: transform;
  user-select: none;
  -webkit-user-select: none;
}

.wall-piece {
  position: absolute;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  transform: rotate(var(--rotation));
}

.wall-piece img { display: block; width: var(--piece-width); border: 1px solid var(--line); }
.wall-piece:hover, .wall-piece.is-selected { z-index: 4; }
.wall-piece.is-selected img { outline: 2px solid var(--black); outline-offset: 7px; }

.zoom-readout {
  position: absolute;
  z-index: 10;
  right: 14px;
  bottom: 12px;
  min-width: 44px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  background: var(--white);
  font-family: 'Courier New', monospace;
  font-size: 9px;
  text-align: center;
}

.random-mode { overflow: auto; background: var(--white); }

.random-stage {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  place-items: center;
  gap: 14px;
  padding: 18px 24px 24px;
}

.random-counter { justify-self: start; margin: 0; font-family: 'Courier New', monospace; font-size: 9px; }
.random-sheet { height: min(60vh, 560px); margin: 0; border: 1px solid var(--line); background: var(--white); }
.random-sheet img { display: block; height: 100%; max-width: 86vw; object-fit: contain; }
.random-actions { display: flex; gap: 10px; }

.random-actions button {
  min-height: 44px;
  padding: 9px 18px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--white);
  cursor: pointer;
  text-transform: uppercase;
  font-family: 'Courier New', monospace;
  font-size: 10px;
}

.random-actions button:hover, .random-actions #secretButton { color: var(--white); background: var(--black); }
.random-actions #secretButton:hover { color: var(--black); background: var(--white); }

.detail-strip {
  position: fixed;
  z-index: 101;
  inset: auto 0 0;
  height: 48px;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  align-items: center;
  border-top: 1px solid var(--line);
  background: var(--white);
}

.detail-strip button { align-self: stretch; border: 0; background: var(--white); cursor: pointer; font-size: 16px; }
.detail-strip button:first-child { border-right: 1px solid var(--line); }
.detail-strip button:last-child { border-left: 1px solid var(--line); }
.detail-strip button:hover { color: var(--white); background: var(--black); }

.detail-strip p {
  margin: 0;
  padding: 0 16px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: center;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 12px;
  font-style: italic;
}

@media (max-width: 760px) {
  .topbar { height: 82px; grid-template-columns: 1fr; }
  .mode-switcher { overflow-x: auto; justify-content: flex-start; }
  .mode-button { min-width: 125px; padding: 9px 10px; font-size: 10px; }
  .source-count { display: none; }
  #app { top: 82px; }
  .doors-mode { padding: 24px 18px; }
  .doors-index h1 { margin-bottom: 38px; font-size: clamp(30px, 11vw, 54px); }
  .doors-grid { grid-template-columns: repeat(4, minmax(48px, 1fr)); grid-auto-rows: 100px; gap: 12px; }
  .door:nth-child(5), .door:nth-child(12), .door:nth-child(14) { grid-column: span 1; }
  .door-room { padding: 14px; }
  .door-room img { max-width: calc(100vw - 28px); max-height: calc(100vh - 90px); }
  .door-room img.is-zoomed { width: 190vw; max-width: none; max-height: none; }
  .drawer-mode.is-active { grid-template-columns: 1fr; }
  .cabinet-wrap { min-height: 500px; padding: 24px; border-right: 0; border-bottom: 1px solid var(--line); }
  .drawer-desk { min-height: 620px; padding: 30px 24px 55px; }
  .page-mount { height: min(62vh, 500px); }
  .random-actions { width: 100%; flex-direction: column; }
  .random-sheet { height: min(52vh, 480px); }
}
