:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-deep: #f5fafa;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-strong: rgba(255, 255, 255, 0.94);
  --surface-subtle: rgba(237, 240, 241, 0.82);
  --border: rgba(0, 106, 113, 0.12);
  --border-strong: rgba(0, 106, 113, 0.34);
  --text: #191c1d;
  --muted: #3f484a;
  --muted-dim: #6f797a;
  --accent: #006a71;
  --accent-dark: #004f54;
  --accent-ink: #ffffff;
  --assistant: #f1f3f4;
  --user: linear-gradient(135deg, #e1fdff 0%, #ffffff 100%);
  --violet: #6041a9;
  --violet-container: #e9ddff;
  --danger: #ba1a1a;
  --glass-blur: blur(22px);
  --panel-shadow: 0 24px 70px rgba(25, 28, 29, 0.14), inset 0 0 0 1px rgba(255, 255, 255, 0.58);
  --soft-shadow: 0 14px 38px rgba(25, 28, 29, 0.09), 0 0 24px rgba(0, 106, 113, 0.06);
  --cyan-glow: 0 0 18px rgba(0, 106, 113, 0.16);
  --violet-glow: 0 0 18px rgba(96, 65, 169, 0.16);
  --font-display: "Montserrat", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "Space Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 16% 10%, rgba(225, 253, 255, 0.82), transparent 30%),
    radial-gradient(circle at 86% 4%, rgba(233, 221, 255, 0.5), transparent 32%),
    linear-gradient(rgba(0, 106, 113, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 106, 113, 0.03) 1px, transparent 1px),
    var(--bg);
  background-size:
    auto,
    auto,
    40px 40px,
    40px 40px;
  color: var(--text);
  font-family: var(--font-body);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--text);
  cursor: pointer;
  padding: 0 12px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease,
    transform 140ms ease;
}

button:hover {
  border-color: var(--border-strong);
  box-shadow: var(--cyan-glow);
  transform: translateY(-1px);
}

button[type="submit"],
#loadButton {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 10px 28px rgba(0, 106, 113, 0.22);
}

button[type="submit"]:hover,
#loadButton:hover {
  background: var(--accent-dark);
}

button:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
  padding: 9px 10px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(0, 106, 113, 0.5);
  box-shadow: 0 0 0 3px rgba(0, 106, 113, 0.12);
}

textarea {
  resize: none;
  height: 52px;
  min-height: 52px;
  max-height: 52px;
  line-height: 1.45;
}

.auth-view {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
}

.auth-view[hidden] {
  display: none;
}

.auth-card {
  width: min(760px, 100%);
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface-strong);
  box-shadow: var(--soft-shadow);
  padding: 26px;
}

.auth-card header {
  margin-bottom: 22px;
}

.auth-card h1,
.auth-card h2,
.auth-card p {
  margin: 0;
}

.auth-card h1 {
  font-family: var(--font-display);
  font-size: 28px;
}

.auth-card p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.auth-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-step {
  display: grid;
  gap: 12px;
}

.auth-step[hidden] {
  display: none;
}

.auth-actions {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 10px;
}

.auth-form h2 {
  font-family: var(--font-display);
  font-size: 16px;
}

.auth-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: 286px minmax(420px, 1fr) 336px;
  gap: 14px;
  width: 100vw;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background: transparent;
  padding: 14px;
}

.app-shell[hidden] {
  display: none;
}

.app-shell.hide-left {
  grid-template-columns: minmax(420px, 1fr) 336px;
}

.app-shell.hide-right {
  grid-template-columns: 286px minmax(420px, 1fr);
}

.app-shell.hide-left.hide-right {
  grid-template-columns: minmax(420px, 1fr);
}

.app-shell.hide-left .sidebar,
.app-shell.hide-right .memory-pane {
  display: none;
}

.sidebar,
.memory-pane {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: calc(100dvh - 28px);
  overflow-y: auto;
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  scrollbar-gutter: stable;
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--soft-shadow);
}

.sidebar {
  padding: 18px;
}

.memory-pane {
  overflow-x: hidden;
}

.brand {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 18px;
  padding-right: 44px;
}

.pane-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.brand-title {
  min-width: 0;
}

.pane-close,
.floating-toggle {
  display: inline-grid;
  place-items: center;
  width: 32px;
  min-width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 12px;
  font-size: 22px;
  line-height: 1;
  color: var(--accent);
  background: rgba(225, 253, 255, 0.78);
  border-color: rgba(0, 106, 113, 0.14);
}

.ui-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pane-close:hover,
.floating-toggle:hover {
  background: rgba(167, 240, 255, 0.58);
  border-color: rgba(0, 106, 113, 0.26);
}

.floating-toggle {
  position: fixed;
  top: 86px;
  z-index: 20;
  width: 42px;
  min-width: 42px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  box-shadow: var(--soft-shadow);
}

.floating-toggle-left {
  left: 0;
  border-left: 0;
  border-radius: 0 16px 16px 0;
}

.floating-toggle-right {
  right: 0;
  border-right: 0;
  border-radius: 16px 0 0 16px;
}

.sidebar > .brand .pane-close {
  position: absolute;
  top: -2px;
  right: 0;
}

.memory-header .pane-close {
  position: absolute;
  top: 14px;
  left: 18px;
}

.floating-toggle[hidden],
.pane-close[hidden],
.mobile-backdrop[hidden] {
  display: none;
}

.mobile-backdrop {
  display: none;
}

.brand h1,
.chat-header h2,
.memory-header h2,
.panel h2 {
  margin: 0;
  letter-spacing: 0;
  font-family: var(--font-display);
}

.brand h1 {
  font-size: 23px;
  line-height: 1.05;
  color: var(--accent);
  text-shadow: 0 0 16px rgba(0, 106, 113, 0.12);
}

.brand p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-family: var(--font-mono);
  letter-spacing: 0;
  text-transform: uppercase;
}

#memoryCount,
.badge {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  min-height: 24px;
  border-radius: 999px;
  background: rgba(225, 253, 255, 0.72);
  color: var(--accent);
  border: 1px solid rgba(0, 106, 113, 0.14);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0;
  padding: 2px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 16px;
}

.panel h2 {
  font-size: 15px;
  margin-bottom: 12px;
  color: var(--text);
}

.panel-help {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
}

.character-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: -2px 0 12px;
}

.room-list {
  display: grid;
  gap: 8px;
}

.room-list:empty::before {
  content: "まだルームはありません";
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.room-item {
  display: grid;
  gap: 4px;
  width: 100%;
  height: auto;
  min-height: 50px;
  justify-items: start;
  padding: 9px 10px;
  text-align: left;
  background: rgba(255, 255, 255, 0.7);
}

.room-item.active {
  border-color: rgba(0, 106, 113, 0.42);
  background: rgba(225, 253, 255, 0.72);
  box-shadow: var(--cyan-glow);
}

.room-item strong {
  color: var(--text);
  font-size: 13px;
  line-height: 1.25;
}

.room-item span {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.35;
}

.room-notice {
  margin: 10px 0 0;
  color: var(--accent);
  font-size: 12px;
  line-height: 1.45;
}

.room-notice[hidden] {
  display: none;
}

.secondary-action {
  width: 100%;
  margin: 0;
  background: rgba(225, 253, 255, 0.62);
  color: var(--accent);
  border-color: rgba(0, 106, 113, 0.14);
}

.logout-button {
  width: 100%;
  min-height: 38px;
  padding: 0 12px;
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
}

.account-panel {
  margin-top: 18px;
}

.account-list {
  display: grid;
  gap: 8px;
  margin: 0 0 12px;
}

.account-list div {
  display: grid;
  gap: 4px;
}

.account-list dt {
  color: var(--muted-dim);
  font-size: 11px;
  font-weight: 600;
}

.account-list dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.4;
}

.advanced-settings {
  margin: 4px 0 12px;
  color: var(--muted);
  font-size: 12px;
}

.advanced-settings summary {
  cursor: pointer;
  padding: 4px 0 8px;
}

.advanced-settings label {
  margin-bottom: 12px;
}

.advanced-settings label:last-child {
  margin-bottom: 0;
}

#advancedRoomFields:not(:empty) {
  margin-bottom: 12px;
}

.profile-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.profile-list div {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 8px;
}

.profile-list dt {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.profile-list dd {
  margin: 0;
  font-size: 14px;
}

.chat-pane {
  min-width: 0;
  min-height: 0;
  height: calc(100dvh - 28px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: var(--glass-blur);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--panel-shadow);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(18px);
  box-shadow: 0 8px 26px rgba(25, 28, 29, 0.08), 0 0 18px rgba(0, 106, 113, 0.06);
  padding: 13px 16px;
  min-height: 68px;
}

.chat-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.chat-header h2 {
  font-size: 18px;
  line-height: 1.15;
  color: var(--text);
}

.chat-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
}

.chat-title > div:last-child {
  min-width: 0;
}

.chat-avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: var(--violet-container);
  color: var(--violet);
  font-weight: 700;
  border: 1px solid rgba(0, 106, 113, 0.18);
  box-shadow: var(--cyan-glow), var(--violet-glow);
}

.view-controls {
  display: none;
}

.mobile-header-button {
  display: none;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 18px 20px 18px;
}

.empty-state {
  display: grid;
  gap: 7px;
  color: var(--muted);
  text-align: center;
  margin-top: 20vh;
  line-height: 1.5;
}

.empty-state strong {
  color: var(--text);
  font-size: 15px;
}

.empty-state span {
  font-size: 13px;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  margin: 10px 0;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.assistant {
  justify-content: flex-start;
}

.message-stack {
  max-width: min(72%, 720px);
  display: grid;
  gap: 5px;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: fit-content;
  max-width: 100%;
  padding: 14px 16px;
  border-radius: 18px;
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 14px;
  overflow-wrap: anywhere;
  box-shadow: 0 14px 30px rgba(25, 28, 29, 0.1);
  backdrop-filter: blur(18px);
}

.message.user {
  margin-left: auto;
  border-bottom-right-radius: 6px;
  background: var(--user);
  border: 1px solid rgba(0, 106, 113, 0.15);
  color: var(--text);
  box-shadow: 0 0 18px rgba(0, 106, 113, 0.08), 0 14px 30px rgba(25, 28, 29, 0.08);
}

.message.assistant {
  margin-right: auto;
  border-bottom-left-radius: 6px;
  background: var(--assistant);
  border: 1px solid rgba(0, 106, 113, 0.08);
  border-left: 4px solid var(--violet);
  box-shadow: -8px 0 24px -16px rgba(96, 65, 169, 0.44), 0 14px 30px rgba(25, 28, 29, 0.1);
}

.message-content {
  min-width: 0;
}

.narration {
  color: var(--violet);
  font-style: italic;
  background: rgba(233, 221, 255, 0.76);
  border: 1px solid rgba(96, 65, 169, 0.16);
  border-radius: 8px;
  padding: 1px 5px;
}

.bubble-avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--violet-container);
  color: var(--violet);
  font-size: 11px;
  font-weight: 700;
  margin-top: 1px;
  box-shadow: var(--violet-glow);
}

.message-meta {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.2;
  letter-spacing: 0;
  text-transform: uppercase;
}

.message-row.user .message-meta {
  display: none;
}

.message-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.2;
  margin-bottom: 2px;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 118px;
  gap: 12px;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(28px);
  padding: 14px 16px;
  min-height: 86px;
  box-shadow: 0 -16px 38px rgba(25, 28, 29, 0.08), 0 0 22px rgba(0, 106, 113, 0.05);
}

.composer textarea {
  border-color: rgba(0, 106, 113, 0.12);
  background: rgba(255, 255, 255, 0.9);
  padding: 12px 14px;
  border-radius: 18px;
  color: var(--text);
}

.composer button {
  align-self: start;
  width: 100%;
}

.composer-buttons {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 8px;
}

.composer-buttons button {
  min-height: 42px;
}

.narration-button {
  padding-inline: 0;
  font-size: 20px;
  line-height: 1;
  color: var(--accent);
  background: rgba(225, 253, 255, 0.72);
  border-color: rgba(0, 106, 113, 0.2);
}

.composer-actions {
  display: grid;
  gap: 5px;
  align-self: start;
}

.composer-actions span {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.25;
  text-align: center;
  letter-spacing: 0;
}

.memory-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(18px);
  padding: 16px 18px 16px 58px;
  min-height: 64px;
}

.memory-header h2 {
  font-size: 17px;
}

.story-state-panel {
  border-bottom: 1px solid var(--border);
  background: rgba(225, 253, 255, 0.52);
  padding: 13px 18px 14px;
}

.story-state-panel[hidden] {
  display: none;
}

.story-state-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.story-state-heading h3 {
  margin: 0;
  font-size: 13px;
  font-family: var(--font-display);
}

.story-state-heading span {
  flex: 0 0 auto;
  border-radius: 999px;
  background: rgba(233, 221, 255, 0.74);
  color: var(--violet);
  border: 1px solid rgba(96, 65, 169, 0.16);
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 3px 7px;
}

.story-state-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.story-state-list div {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 8px;
}

.story-state-list dt {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.story-state-list dd {
  min-width: 0;
  margin: 0;
  color: var(--text);
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.context-memory,
.memory-list {
  padding: 12px 18px;
}

.context-memory {
  display: none;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 225, 115, 0.18);
}

.context-memory.active {
  display: block;
}

.context-memory h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text);
}

.memory-item {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 11px 12px;
  margin-bottom: 10px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(14px);
}

.memory-item:last-child {
  margin-bottom: 0;
}

.memory-item p {
  margin: 0;
  line-height: 1.45;
  font-size: 13px;
}

.memory-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.error {
  color: var(--danger);
}

.character-dialog {
  width: min(760px, calc(100vw - 28px));
  max-height: min(820px, calc(100dvh - 28px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--panel-shadow);
  backdrop-filter: var(--glass-blur);
}

.character-dialog::backdrop {
  background: rgba(63, 72, 74, 0.18);
  backdrop-filter: blur(6px);
}

.character-form {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  max-height: min(820px, calc(100dvh - 28px));
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 16px 18px;
  background: rgba(255, 255, 255, 0.72);
}

.dialog-header h2,
.character-form h3 {
  margin: 0;
  letter-spacing: 0;
}

.dialog-header h2 {
  font-size: 18px;
}

.dialog-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.character-form-body {
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px 4px;
}

.character-form section {
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
  margin-bottom: 14px;
}

.draft-section {
  background: rgba(225, 253, 255, 0.46);
  border: 1px solid rgba(0, 106, 113, 0.12);
  border-radius: 18px;
  padding: 14px;
}

.draft-section .secondary-action {
  min-height: 42px;
}

.draft-review {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  border: 1px solid rgba(96, 65, 169, 0.16);
  border-radius: 14px;
  background: rgba(233, 221, 255, 0.52);
  padding: 12px;
}

.draft-review[hidden] {
  display: none;
}

.draft-review h3,
.draft-review h4 {
  margin: 0;
  letter-spacing: 0;
}

.draft-review h3 {
  color: var(--violet);
  font-size: 13px;
}

.draft-review h4 {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
}

.draft-review ul {
  margin: 5px 0 0;
  padding-left: 18px;
}

.draft-review li {
  margin: 3px 0;
  font-size: 12px;
  line-height: 1.45;
}

.draft-review-meta {
  margin: 0;
  color: var(--muted-dim);
  font-family: var(--font-mono);
  font-size: 10px;
}

.character-form section:last-child {
  border-bottom: 0;
}

.character-form h3 {
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--accent);
  font-family: var(--font-display);
}

.character-form textarea {
  height: auto;
  min-height: 0;
  max-height: none;
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.checkbox-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-family: var(--font-body);
  letter-spacing: 0;
  text-transform: none;
}

.checkbox-row input {
  width: auto;
  min-height: 0;
}

.form-error {
  margin: 0;
  padding: 0 18px 12px;
  color: var(--danger);
  font-size: 13px;
}

.dialog-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 10px;
  border-top: 1px solid var(--border);
  padding: 14px 18px 16px;
  background: rgba(255, 255, 255, 0.72);
}

.dialog-actions button {
  min-height: 42px;
  width: 100%;
}

@media (max-width: 980px) {
  .auth-view {
    align-items: stretch;
    padding: 14px;
  }

  .auth-card {
    display: grid;
    align-content: center;
    min-height: calc(100dvh - 28px);
    padding: 20px;
  }

  .auth-grid {
    grid-template-columns: 1fr;
  }

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

  body {
    background:
      radial-gradient(circle at 18% 0%, rgba(225, 253, 255, 0.86), transparent 30%),
      linear-gradient(rgba(0, 106, 113, 0.03) 1px, transparent 1px),
      linear-gradient(90deg, rgba(0, 106, 113, 0.03) 1px, transparent 1px),
      var(--bg);
    background-size: auto, 40px 40px, 40px 40px;
  }

  .app-shell {
    display: block;
    width: 100vw;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    padding: 0;
  }

  .app-shell.hide-left,
  .app-shell.hide-right,
  .app-shell.hide-left.hide-right {
    grid-template-columns: 1fr;
  }

  .app-shell.hide-left .sidebar,
  .app-shell.hide-right .memory-pane {
    display: block;
  }

  .floating-toggle {
    display: none;
  }

  .sidebar,
  .memory-pane {
    position: fixed;
    top: 0;
    bottom: 0;
    display: block;
    width: min(86vw, 380px);
    max-width: 100vw;
    height: 100dvh;
    z-index: 40;
    border: 0;
    border-radius: 0;
    box-shadow: var(--panel-shadow);
    transition: transform 180ms ease;
    scrollbar-gutter: auto;
    overscroll-behavior: contain;
  }

  .sidebar {
    left: 0;
    padding: calc(14px + env(safe-area-inset-top)) 16px 16px;
    border-right: 1px solid var(--border);
  }

  .memory-pane {
    right: 0;
    border-left: 1px solid var(--border);
  }

  .app-shell.hide-left .sidebar {
    transform: translateX(-104%);
    pointer-events: none;
  }

  .app-shell:not(.hide-left) .sidebar {
    transform: translateX(0);
  }

  .app-shell.hide-right .memory-pane {
    transform: translateX(104%);
    pointer-events: none;
  }

  .app-shell:not(.hide-right) .memory-pane {
    transform: translateX(0);
  }

  .chat-pane {
    width: 100vw;
    height: 100dvh;
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr) auto;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: rgba(255, 255, 255, 0.72);
  }

  .chat-header {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    align-items: center;
    gap: 8px;
    min-height: calc(56px + env(safe-area-inset-top));
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  }

  .chat-title {
    min-width: 0;
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .chat-title > div:last-child {
    min-width: 0;
    max-width: 100%;
  }

  .chat-avatar {
    display: none;
  }

  .chat-header h2 {
    overflow: hidden;
    font-size: 16px;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chat-header p {
    overflow: hidden;
    font-size: 11px;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-header-button {
    display: grid;
    place-items: center;
    width: 44px;
    min-width: 44px;
    height: 40px;
    min-height: 40px;
    padding: 0;
    border-radius: 14px;
    color: var(--accent);
    font-weight: 700;
    line-height: 1;
    background: rgba(225, 253, 255, 0.72);
  }

  .pane-close {
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
  }

  .mobile-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: block;
    width: 100%;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgba(63, 72, 74, 0.2);
    backdrop-filter: blur(4px);
    cursor: default;
    transform: none;
  }

  .mobile-backdrop:hover {
    border-color: transparent;
    transform: none;
  }

  .messages {
    min-height: 0;
    padding: 12px 10px;
    scrollbar-gutter: auto;
  }

  .message-stack {
    max-width: min(86%, 640px);
  }

  .message-time {
    display: none;
  }

  .message {
    font-size: 14px;
    line-height: 1.45;
    padding: 12px 13px;
  }

  .composer {
    grid-template-columns: 1fr;
    gap: 8px;
    min-height: 0;
    padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
  }

  .composer textarea {
    height: 48px;
    min-height: 48px;
    max-height: 96px;
    border-radius: 16px;
    font-size: 16px;
  }

  .composer-actions span {
    display: none;
  }

  .composer-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    align-self: stretch;
  }

  .composer-buttons {
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 8px;
  }

  .composer-buttons button {
    min-height: 44px;
    border-radius: 14px;
  }

  .narration-button {
    font-size: 22px;
  }

  .button-row {
    grid-template-columns: 1fr;
  }

  .brand {
    align-items: start;
    margin-bottom: 14px;
    padding-right: 48px;
  }

  .brand h1 {
    font-size: 21px;
  }

  .panel {
    margin-top: 14px;
    padding-top: 14px;
  }

  input,
  select,
  .character-form textarea {
    min-height: 42px;
    font-size: 16px;
  }

  .character-dialog {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .character-form {
    height: 100dvh;
    max-height: 100dvh;
  }

  .dialog-header {
    padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
  }

  .character-form-body {
    padding: 14px 14px 4px;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .dialog-actions {
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 640px) {
  .chat-header h2 {
    font-size: 15px;
  }

  .bubble-avatar {
    display: none;
  }

  .message-stack {
    max-width: 90%;
  }

  .message-row {
    margin: 4px 0;
  }
}

@media (max-width: 980px) and (max-height: 520px) {
  .chat-header {
    min-height: 52px;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .messages {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) 104px;
    gap: 8px;
    padding-top: 8px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .composer textarea {
    height: 48px;
    min-height: 48px;
    max-height: 48px;
  }

  .composer-buttons {
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 6px;
  }

  .composer-buttons button {
    min-height: 48px;
  }
}
