* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: #fff;
  color: #000;
  color-scheme: light;
  font-family: system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  padding-top: max(6px, env(safe-area-inset-top));
  border-bottom: 1px solid #000;
  flex: 0 0 auto;
}

.header-right { display: flex; align-items: center; gap: 10px; }

main { flex: 1; min-height: 0; display: flex; }

.screen { display: none; width: 100%; min-height: 0; }
.screen.active { display: block; }
#screen-home.active, #screen-lobby.active { overflow-y: auto; }
#screen-game.active { display: flex; }

.pane {
  max-width: 640px;
  padding: 12px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 14px; margin: 16px 0 4px; }
p { margin: 8px 0; }

label { display: block; font-size: 13px; }
label:has(> input[type="checkbox"]) { display: flex; gap: 8px; align-items: flex-start; }
input[type="checkbox"] { min-height: 0; width: 18px; height: 18px; flex: 0 0 auto; margin: 1px 0 0; }

input, select, button {
  font: inherit;
  font-size: 16px;
  min-height: 44px;
  padding: 6px 8px;
  border: 1px solid #000;
  background: #fff;
  color: #000;
}

button { cursor: pointer; }
button:disabled { color: #888; border-color: #888; cursor: not-allowed; }

fieldset { border: 1px solid #000; padding: 8px 10px; margin: 14px 0; }
legend { font-size: 13px; }

.field-row { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 8px; flex-wrap: wrap; }
.field { flex: 1; min-width: 130px; }
.field select, .field input { width: 100%; }
.field-row > input { flex: 1; min-width: 90px; }
.wide { width: 100%; }
.ai-seat { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.ai-seat span { width: 44px; font-size: 13px; }
.ai-seat select { flex: 1; min-width: 0; }

ul { list-style: none; margin: 0 0 10px; padding: 0; }

li {
  padding: 6px 0;
  display: flex;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid #ddd;
}

li.dead { text-decoration: line-through; color: #888; }
li.offline { color: #888; }

.grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 12px; color: #555; }
.hint { font-size: 13px; color: #555; }
.error { font-size: 14px; min-height: 18px; }
.code { font-variant-numeric: tabular-nums; font-weight: bold; }

#chat { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }

#phase-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid #000;
  flex: 0 0 auto;
}

.phase-right { display: flex; align-items: center; gap: 10px; }
#phase-timer { font-variant-numeric: tabular-nums; }
#btn-drawer { display: none; }

#messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px;
}

.msg { margin-bottom: 5px; overflow-wrap: anywhere; }
.msg .author { font-weight: bold; margin-right: 6px; }
.msg.system { color: #555; font-size: 13px; }
.msg.private { border-left: 3px solid #000; padding-left: 6px; }
.msg img { max-width: 200px; display: block; margin-top: 4px; }

#composer {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid #000;
  flex: 0 0 auto;
}

#composer input { flex: 1; min-width: 0; }

#spectator-bar {
  margin: 0;
  padding: 8px 10px;
  border-top: 1px solid #000;
  font-size: 13px;
  flex: 0 0 auto;
}

#sidebar {
  width: 240px;
  flex: 0 0 240px;
  border-left: 1px solid #000;
  padding: 10px;
  overflow-y: auto;
}

.drawer-head { display: flex; justify-content: space-between; align-items: center; }
.drawer-head h2 { margin: 0 0 6px; }
#btn-drawer-close { display: none; }

#vote-options button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-bottom: 4px;
  text-align: left;
}

#vote-options button.chosen { font-weight: bold; border-width: 3px; }
.vote-count { margin-left: auto; }

#result-banner { border: 1px solid #000; padding: 8px; text-align: center; font-weight: bold; }

.modal {
  position: fixed;
  inset: 0;
  background: #fff;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12px;
  z-index: 20;
  overflow-y: auto;
}

.modal-body { width: 100%; max-width: 640px; }
.modal-head { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.modal-head h2 { margin: 0; flex: 1; }
.modal-head input { flex: 1; min-width: 0; }

#gif-results { display: flex; flex-wrap: wrap; gap: 4px; }
#gif-results img { width: 110px; height: 84px; object-fit: cover; cursor: pointer; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 5px 4px; border-bottom: 1px solid #ddd; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
  #btn-drawer, #btn-drawer-close { display: inline-block; }

  #sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(300px, 85vw);
    flex: none;
    background: #fff;
    border-left: 1px solid #000;
    z-index: 30;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    display: none;
  }

  #sidebar.open { display: block; }

  #drawer-scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 25; }

  #gif-results img { width: calc(50% - 2px); }
}
