* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: "Segoe UI", sans-serif;
  color: #142033;
  background: #e8eef6;
}
button, input { font: inherit; }
#gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(circle at 20% 10%, #ffffff, transparent 40%),
    linear-gradient(160deg, #d7e6f8, #eef3ea 55%, #f7f4ea);
}
.card {
  width: min(440px, 100%);
  background: #fff;
  border-radius: 18px;
  padding: 28px 24px 20px;
  box-shadow: 0 16px 50px rgba(20, 40, 70, 0.12);
}
.mark {
  margin: 0;
  color: #1d4e89;
  font-weight: 700;
  letter-spacing: 0.04em;
}
h1 { margin: 6px 0 8px; font-size: 28px; }
.lead, .fine { color: #526277; line-height: 1.45; }
.fine { font-size: 13px; margin-bottom: 0; }
.tabs { display: flex; gap: 8px; margin: 18px 0; flex-wrap: wrap; }
.tabs a {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 10px 14px;
  background: #e8eef6;
  color: #1d4e89;
  text-decoration: none;
}
.tabs button, #logout, #settings, #door, #say button, .go, #settings-panel button {
  border: 0;
  border-radius: 999px;
  padding: 10px 14px;
  background: #e8eef6;
  color: #1d4e89;
  cursor: pointer;
}
.tabs button.on, .go, #say button, #door {
  background: #1d4e89;
  color: #fff;
}
.go, #say button { width: 100%; margin-top: 8px; }
label { display: block; font-size: 14px; margin: 10px 0; }
input {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid #d5deea;
  border-radius: 10px;
}
.error { min-height: 1.2em; color: #9f1239; }
#stage { position: fixed; inset: 0; background: #b9d4ee; }
#view { width: 100%; height: 100%; display: block; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#hud, #place-count, #door, #log, #say, #stick, #help, #settings-panel {
  position: absolute;
  z-index: 2;
}
#hud {
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
#hud div, #log, #say, #place-count, #help {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(20, 32, 51, 0.12);
}
#hud div { padding: 8px 12px; }
#where { display: block; color: #526277; font-size: 13px; }
#hud #hud-actions {
  display: flex;
  gap: 8px;
  padding: 0;
  background: transparent;
  box-shadow: none;
}
#settings, #logout { background: #fff; }
#settings-panel {
  top: 64px;
  right: 12px;
  width: min(320px, calc(100% - 24px));
  max-height: min(72vh, 680px);
  overflow: auto;
  margin: 0;
  padding: 12px;
  background: rgba(255, 255, 255, 0.96);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(20, 32, 51, 0.12);
}
#settings-panel p { margin: 10px 0 6px; font-size: 13px; color: #526277; font-weight: 700; }
#settings-panel p:first-child { margin-top: 0; }
#settings-panel .pick { display: flex; flex-wrap: wrap; gap: 6px; }
#settings-panel .pick button { width: auto; margin: 0; padding: 7px 10px; font-size: 13px; }
#settings-panel button.on { background: #1d4e89; color: #fff; }
#place-count { top: 74px; left: 12px; margin: 0; padding: 6px 10px; font-size: 13px; }
#door { left: 50%; bottom: 92px; transform: translateX(-50%); padding: 12px 22px; }
#log {
  right: 12px;
  bottom: 78px;
  width: min(320px, 46vw);
  max-height: min(360px, 46vh);
  overflow: auto;
  padding: 10px 12px;
  font-size: 14px;
}
#log p { margin: 4px 0; }
#log button {
  border: 0;
  background: transparent;
  color: #1d4e89;
  padding: 0;
  cursor: pointer;
}
#log-size { display: none; }
#say {
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  width: min(520px, calc(100% - 24px));
  padding: 8px;
}
#say input { margin: 0; }
#say button { width: auto; margin: 0; }
#stick {
  left: 16px;
  bottom: 16px;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  border: 2px solid rgba(29, 78, 137, 0.35);
  touch-action: none;
}
#knob {
  width: 46px;
  height: 46px;
  margin: 33px;
  border-radius: 50%;
  background: #1d4e89;
}
#help {
  left: 140px;
  bottom: 86px;
  margin: 0;
  padding: 8px 10px;
  font-size: 13px;
  max-width: 240px;
}
#touch-hint { display: none; }
@media (max-width: 700px) {
  #help { display: none; }
  #log {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    left: auto;
    right: 12px;
    width: min(280px, calc(100% - 24px));
    bottom: calc(132px + env(safe-area-inset-bottom));
    max-height: none;
    overflow: visible;
    padding: 0 2px;
    background: transparent;
    box-shadow: none;
    font-size: 14px;
    pointer-events: none;
  }
  #log #log-size {
    display: inline-flex;
    align-self: flex-end;
    pointer-events: auto;
    margin: 0 0 4px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.55);
    color: #0c1b30;
    font-size: 12px;
    font-weight: 700;
  }
  #log-lines { pointer-events: none; }
  #log p, #log-lines button {
    pointer-events: auto;
    color: #071422;
    font-weight: 700;
    line-height: 1.35;
    text-shadow:
      -1px -1px 0 #fff,
      1px -1px 0 #fff,
      -1px 1px 0 #fff,
      1px 1px 0 #fff,
      0 0 6px #fff,
      0 0 12px rgba(255, 255, 255, 0.95);
  }
  #log-lines button { color: #0b3a78; font-weight: 800; }
  #log:not(.mini) #log-lines {
    overflow: auto;
    max-height: min(240px, 34vh);
    touch-action: pan-y;
    pointer-events: auto;
  }
  #log.mini #log-lines { overflow: visible; max-height: none; }
  #log.mini #log-lines p { display: none; }
  #log.mini #log-lines p:nth-last-child(-n+3) { display: block; }
  #touch-hint {
    display: block;
    position: absolute;
    left: 12px;
    right: 12px;
    top: calc(72px + env(safe-area-inset-top));
    bottom: auto;
    margin: 0;
    text-align: center;
    color: #475569;
    font-size: 12px;
    pointer-events: none;
  }
  #say {
    left: 128px;
    right: 12px;
    width: auto;
    transform: none;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }
  #stick { bottom: calc(12px + env(safe-area-inset-bottom)); }
  #door {
    left: 16px;
    transform: none;
    bottom: calc(136px + env(safe-area-inset-bottom));
  }
  #hud { top: calc(8px + env(safe-area-inset-top)); }
  #settings-panel { top: calc(64px + env(safe-area-inset-top)); }
}
