/*
 * base.css — structural rules for the Sharpee browser client.
 *
 * Owner: @sharpee/platform-browser (the published browser engine layer).
 *
 * Per ADR-170, this file owns the layout, positioning, scroll, and
 * state-modifier wiring shared by every theme. It contains no colors,
 * fonts, or visual decoration — those live in engine.css (token-consuming
 * defaults) and per-theme `@sharpee/theme-*` packages (ADR-188).
 *
 * Load order (ADR-188): base.css → engine.css → [theme packages] →
 * [author override]. base.css is purely structural, so its position
 * relative to engine.css is not load-bearing, but it ships first by
 * convention.
 */

/* ----- Reset ----- */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  cursor: pointer;
}

ul, ol, menu {
  list-style: none;
}

/* ----- Window shell ----- */

.sharpee-window {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 80ch;
  margin: 0 auto;
}

@supports (height: 100dvh) {
  .sharpee-window {
    height: 100dvh;
  }
}

.sharpee-window-title-bar {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.sharpee-window-title-bar-controls {
  margin-left: auto;
  display: flex;
  align-items: center;
}

/* ----- Menu bar ----- */

.sharpee-menu-bar {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  height: 28px;
  font-size: 14px;
}

.sharpee-menu-bar-item {
  position: relative;
}

.sharpee-menu-bar-trigger {
  padding: 4px 10px;
}

/* Dropdowns hidden by default; shown when the parent item has --open
   or, for nested submenus, when its parent option is hovered. */

.sharpee-menu-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 160px;
  z-index: 1000;
}

.sharpee-menu-bar-item--open > .sharpee-menu-dropdown {
  display: block;
}

.sharpee-menu-dropdown .sharpee-menu-dropdown {
  top: 0;
  left: 100%;
}

.sharpee-menu-option:hover > .sharpee-menu-dropdown,
.sharpee-menu-option:focus-within > .sharpee-menu-dropdown {
  display: block;
}

.sharpee-menu-option {
  padding: 6px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}

.sharpee-menu-option--checked::before {
  content: "\2713";
  margin-right: 8px;
}

.sharpee-menu-option--disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.sharpee-menu-separator {
  height: 1px;
  margin: 4px 8px;
  list-style: none;
}

.sharpee-menu-submenu-indicator {
  margin-left: 12px;
}

/* ----- Status bar ----- */

.sharpee-status-bar {
  display: flex;
  justify-content: space-between;
  flex-shrink: 0;
  padding: 4px 8px;
}

/* ----- Prose pane ----- */

.sharpee-prose-pane {
  position: relative;
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  padding-bottom: 1em;
}

.sharpee-prose-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Continuation entries — emitted by the main channel renderer when a
   block carries `tight: true`. Collapses the inter-paragraph margin so
   the line stacks flush against its predecessor. Used where a former
   intra-block `\n` was lifted to a block boundary (book text under its
   prefix, banner lines under a title). */
.sharpee-prose-pane p.main-entry--tight {
  margin-top: 0;
  margin-bottom: 0;
}

/* ----- Opening banner (structured pieces) ----- */
/* Each piece below is a `<p class="main-entry {name}">` emitted by the
   engine's `buildBannerBlocks`. Defaults keep them flush; themes may
   override font weight, size, alignment. The `banner-spacer` is the
   only piece that occupies vertical space — it's an empty `<p>` whose
   height supplies the visual gap between the credits and any
   story-defined tail (instructions / tagline). */

.sharpee-prose-pane p.game-title,
.sharpee-prose-pane p.story-version,
.sharpee-prose-pane p.platform-version,
.sharpee-prose-pane p.sub-title,
.sharpee-prose-pane p.author-list {
  margin-top: 0;
  margin-bottom: 0;
}

.sharpee-prose-pane p.banner-spacer {
  margin-top: 0;
  margin-bottom: 0;
  /* Empty <p> — render its line-height as the visual gap. */
  min-height: 1em;
}

/* Game title default — bold, slightly larger. Themes may override. */
.sharpee-prose-pane p.game-title {
  font-weight: bold;
}

/* ----- Input bar ----- */

.sharpee-input-bar {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  padding: 4px 8px;
}

.sharpee-input-prompt {
  margin-right: 4px;
}

.sharpee-input-field {
  flex: 1;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  outline: 0;
}

/* ----- Dialogs (native <dialog>) ----- */

.sharpee-dialog {
  padding: 0;
  border: 0;
  min-width: 300px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.sharpee-dialog:not([open]) {
  display: none;
}

.sharpee-dialog-title {
  padding: 4px 8px;
  font-weight: bold;
  text-align: center;
  font-size: inherit;
}

.sharpee-dialog-body {
  padding: 12px;
  flex: 1;
  overflow-y: auto;
}

.sharpee-dialog-buttons {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 12px;
}

.sharpee-dialog-button {
  padding: 6px 20px;
  min-width: 80px;
}

.sharpee-dialog-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* ----- Multi-user surfaces (ADR-176) ----- */

/* Presence */

.sharpee-presence-panel {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.sharpee-presence-list {
  display: flex;
  flex-direction: column;
}

.sharpee-presence-item {
  display: flex;
  align-items: center;
  padding: 4px 8px;
}

.sharpee-presence-avatar {
  flex-shrink: 0;
  margin-right: 8px;
}

/* Chat */

.sharpee-chat-panel {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sharpee-chat-history {
  flex: 1;
  overflow-y: auto;
  overflow-anchor: auto; /* scroll-pin to bottom on new content */
  padding: 8px;
  display: flex;
  flex-direction: column;
}

.sharpee-chat-message {
  padding: 2px 0;
  display: block;
}

.sharpee-chat-message-author {
  font-weight: bold;
  margin-right: 4px;
}

.sharpee-chat-message-text {
  display: inline;
}

.sharpee-chat-input {
  flex-shrink: 0;
  width: 100%;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  outline: 0;
  padding: 4px 8px;
}

/* Lock-on-typing */

.sharpee-lock-banner {
  flex-shrink: 0;
  padding: 2px 8px;
  font-style: italic;
}

.sharpee-lock-banner--hidden {
  display: none;
  pointer-events: none;
}

.sharpee-input-bar--locked .sharpee-input-field {
  pointer-events: none;
}

.sharpee-input-bar--locked .sharpee-input-field:read-only,
.sharpee-input-bar--locked .sharpee-input-field[readonly] {
  cursor: not-allowed;
}

/* Lobby */

.sharpee-lobby {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.sharpee-lobby--hidden {
  display: none;
  pointer-events: none;
}

.sharpee-lobby-list {
  display: flex;
  flex-direction: column;
}

.sharpee-lobby-item {
  padding: 8px;
  cursor: pointer;
}

/* Named saves */

.sharpee-saves-panel {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sharpee-saves-panel--hidden {
  display: none;
  pointer-events: none;
}

.sharpee-saves-list {
  display: flex;
  flex-direction: column;
}

.sharpee-saves-item {
  padding: 6px 8px;
  cursor: pointer;
}

/* Identity form */

.sharpee-identity-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 320px;
  margin: 32px auto;
  padding: 16px;
}

/* Transient-panel --hidden modifier (shared semantics with ADR-170) */

.sharpee-presence-panel--hidden,
.sharpee-chat-panel--hidden {
  display: none;
  pointer-events: none;
}

/* ----- Mobile structural adjustments ----- */

@media (max-width: 600px) {
  .sharpee-window {
    max-width: 100%;
  }

  .sharpee-status-bar {
    padding-top: max(6px, env(safe-area-inset-top));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .sharpee-prose-pane {
    padding: 12px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .sharpee-input-bar {
    padding: 8px 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    min-height: 48px;
  }

  .sharpee-input-field {
    font-size: 16px; /* prevent iOS zoom on focus */
    padding: 8px 0;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .sharpee-status-bar {
    padding: 2px 8px;
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }

  .sharpee-prose-pane {
    padding: 4px 8px;
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }

  .sharpee-input-bar {
    padding: 4px 8px;
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
    min-height: 36px;
  }
}

@media (pointer: coarse) {
  .sharpee-input-field {
    padding: 12px 0;
  }

  .sharpee-input-bar {
    min-height: 52px;
  }
}
