:root {
  --bg: #101820;
  --panel: #17212a;
  --panel-strong: #1d2a35;
  --line: #344858;
  --lcd: #d8f3a2;
  --lcd-dark: #263612;
  --text: #f8fbfd;
  --muted: #9eb0bf;
  --accent: #f4b942;
  --danger: #f16464;
  --ok: #74d680;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  display: grid;
  place-items: center;
}

body.room-selecting .app-shell {
  display: none;
}

body.in-room .room-gate {
  display: none;
}

button,
select {
  font: inherit;
}

.app-shell {
  width: min(100%, 480px);
  min-height: 100svh;
  padding: max(14px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto minmax(176px, 28svh) auto 1fr;
  gap: 12px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.04), transparent 30%),
    var(--bg);
}

.room-gate {
  width: min(100%, 480px);
  min-height: 100svh;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  background: var(--bg);
}

.room-card {
  width: 100%;
  max-height: calc(100svh - 36px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: var(--panel);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 18px;
}

.room-card h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
}

.room-actions,
.room-actions form {
  display: grid;
  gap: 10px;
}

.room-actions input,
.room-actions button,
.room-strip button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #22303b;
  color: var(--text);
  font: inherit;
}

.room-actions input {
  padding: 0 14px;
  outline: none;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

#createRoomButton,
.room-actions form button {
  background: var(--accent);
  color: #201600;
  border-color: #d39824;
  font-weight: 800;
}

.room-directory {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.room-directory-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.room-directory h2 {
  margin: 0;
  font-size: 16px;
}

#roomListStatus {
  color: var(--muted);
  font-size: 13px;
}

.room-list {
  min-width: 0;
  min-height: 76px;
  max-height: min(42svh, 340px);
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  overscroll-behavior: contain;
}

.room-list-item {
  width: 100%;
  min-width: 0;
  min-height: 54px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #22303b;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.room-number {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 20px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.room-occupancy,
.room-list-message {
  color: var(--muted);
  font-size: 13px;
}

.room-occupancy {
  flex: 0 0 auto;
  white-space: nowrap;
}

.room-occupancy.online {
  color: var(--ok);
}

.room-list-message {
  margin: 18px 0;
  text-align: center;
}

.room-strip {
  display: flex;
  justify-content: center;
}

.room-strip button {
  min-height: 36px;
  padding: 0 14px;
  color: var(--muted);
  background: transparent;
}

.lcd-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--line);
  background: var(--panel);
  gap: 0;
  overflow: hidden;
}

.lcd-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 7px;
  background: var(--panel);
  display: grid;
  grid-template-rows: 18px 1fr;
  gap: 5px;
  border-color: var(--line);
  border-style: solid;
  border-width: 0;
  overflow: visible;
}

.lcd-panel.active {
  background: var(--panel-strong);
  z-index: 3;
}

.lcd-panel[data-slot="0"],
.lcd-panel[data-slot="2"] {
  border-right-width: 1px;
}

.lcd-panel[data-slot="0"],
.lcd-panel[data-slot="1"] {
  border-bottom-width: 1px;
}

.screen-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #52606b;
}

.status-dot.online {
  background: var(--ok);
}

.lcd-value {
  position: relative;
  z-index: 1;
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(216, 243, 162, .35);
  background:
    linear-gradient(180deg, rgba(255,255,255,.16), transparent 24%),
    var(--lcd);
  color: var(--lcd-dark);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 8px;
  font-family: "Arial Narrow", "DIN Alternate", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(26px, 13vw, 56px);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  overflow: hidden;
  white-space: nowrap;
}

.lcd-panel.borrow-right .lcd-value,
.lcd-panel.borrow-left .lcd-value {
  position: absolute;
  top: 30px;
  bottom: 7px;
  width: calc(200% - 14px);
  z-index: 4;
}

.lcd-panel.borrow-right .lcd-value {
  left: 7px;
}

.lcd-panel.borrow-left .lcd-value {
  right: 7px;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr;
}

.toolbar button {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}

.mode-button {
  color: #1d1604;
  background: var(--accent) !important;
  border-color: #d39824 !important;
  font-weight: 700;
}

.voice-button[aria-pressed="false"] {
  color: var(--muted);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: minmax(62px, 1fr);
  gap: 8px;
}

.keypad button {
  min-width: 0;
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #22303b;
  color: var(--text);
  font-size: 30px;
  font-weight: 700;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.keypad button:active {
  transform: translateY(1px);
  filter: brightness(1.15);
}

.keypad .operator {
  background: #31424d;
  color: var(--accent);
}

.keypad .backspace {
  background: #403440;
  color: #ffd0e3;
}

.keypad .clear {
  background: #42292a;
  color: #ffd2d2;
}

.keypad .mode-button {
  background: var(--accent);
  color: #201600;
  border-color: #d39824;
  font-size: 17px;
  line-height: 1.12;
  white-space: normal;
}

.keypad .equal {
  background: #293744;
  color: var(--accent);
}

.keypad .h-plus {
  background: #2f473a;
  color: #d8f3a2;
  font-size: 21px;
}

@media (max-height: 740px) {
  .app-shell {
    grid-template-rows: auto minmax(150px, 25svh) auto 1fr;
    gap: 8px;
  }

  .keypad {
    gap: 6px;
    grid-auto-rows: minmax(52px, 1fr);
  }

  .keypad button {
    min-height: 52px;
    font-size: 27px;
  }
}
