:root {
  color-scheme: light dark;
  --bg: #f5f5f3;
  --surface: #ffffff;
  --surface-2: #ececea;
  --text: #17181b;
  --muted: #6d7078;
  --border: #d9dad7;
  --accent: #3867e8;
  --accent-text: #ffffff;
  --danger: #b42318;
  --shadow: 0 12px 35px rgb(20 24 35 / 8%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1a1d24;
    --surface-2: #252932;
    --text: #f3f4f6;
    --muted: #9ca2ad;
    --border: #303540;
    --accent: #7396ff;
    --accent-text: #09122d;
    --danger: #ff8a80;
    --shadow: 0 14px 40px rgb(0 0 0 / 22%);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

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

button,
select,
input {
  min-height: 44px;
}

button {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  padding: 0.6rem 0.85rem;
  touch-action: manipulation;
}

button:hover {
  background: var(--surface-2);
}

button:disabled {
  cursor: wait;
  opacity: 0.55;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.app {
  width: min(100% - 2rem, 760px);
  margin: 0 auto;
  padding: max(1.25rem, env(safe-area-inset-top)) 0 max(3rem, env(safe-area-inset-bottom));
}

.topbar {
  margin-bottom: 1rem;
}

.brand-row,
.room-row,
.top-actions,
.composer-footer,
.section-heading,
.setting-row,
.clip-meta,
.clip-actions {
  display: flex;
  align-items: center;
}

.brand-row,
.room-row,
.composer-footer,
.section-heading,
.setting-row {
  justify-content: space-between;
}

.brand-row h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.connection::before {
  width: 0.48rem;
  height: 0.48rem;
  border-radius: 50%;
  background: #d99b25;
  content: "";
}

.connection[data-state="online"]::before {
  background: #27a467;
}

.connection[data-state="offline"]::before {
  background: #d14b42;
}

.room-row {
  gap: 0.75rem;
  margin-top: 0.8rem;
  flex-wrap: wrap;
}

.room-code {
  min-width: 8.8rem;
  border: 0;
  background: transparent;
  padding-inline: 0;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(1.35rem, 6vw, 1.85rem);
  font-weight: 750;
  letter-spacing: 0.14em;
  text-align: left;
}

.room-code:hover {
  background: transparent;
  color: var(--accent);
}

.top-actions {
  gap: 0.45rem;
}

.icon-button {
  display: inline-grid;
  width: 44px;
  height: 44px;
  min-width: 44px;
  padding: 0;
  place-items: center;
  flex: 0 0 44px;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.panel,
.composer,
.clip-card {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  margin-bottom: 0.9rem;
  padding: 1rem;
}

.qr-panel {
  text-align: center;
}

.qr-panel img {
  display: block;
  width: min(220px, 100%);
  height: auto;
  margin: 0 auto;
  border-radius: 10px;
  background: white;
}

.qr-panel p {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.join-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
}

input,
select,
textarea {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}

input,
select {
  padding: 0.55rem 0.75rem;
}

.join-form input {
  min-width: 0;
  text-transform: uppercase;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.14em;
}

.full-button {
  width: 100%;
  margin-top: 0.65rem;
}

.settings {
  display: grid;
  gap: 0.8rem;
}

.setting-row {
  min-height: 44px;
  gap: 1rem;
}

.switch-row input {
  width: 1.35rem;
  min-height: 1.35rem;
  accent-color: var(--accent);
}

.password-row {
  display: grid;
  gap: 0.4rem;
  padding-top: 0.2rem;
}

.password-row small,
#input-hint,
.section-heading span,
.clip-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.composer {
  position: relative;
  padding: 0.85rem;
  transition: border-color 0.15s, transform 0.15s;
}

.composer.dragging {
  border-color: var(--accent);
  transform: scale(1.01);
}

textarea {
  display: block;
  width: 100%;
  min-height: 10.5rem;
  resize: vertical;
  border: 0;
  background: transparent;
  padding: 0.35rem;
  line-height: 1.6;
}

textarea:focus-visible {
  outline: 0;
}

.image-preview {
  position: relative;
  padding: 0.5rem 0;
}

.image-preview img {
  display: block;
  max-width: 100%;
  max-height: 260px;
  border-radius: 12px;
  object-fit: contain;
}

.image-preview button {
  margin-top: 0.55rem;
}

.clipboard-suggestion {
  width: 100%;
  margin: 0.5rem 0;
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  color: var(--accent);
}

.composer-footer {
  gap: 0.75rem;
  border-top: 1px solid var(--border);
  padding-top: 0.8rem;
}

#input-hint {
  min-width: 0;
}

.primary {
  flex: 0 0 auto;
  min-width: 5.5rem;
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}

.primary:hover {
  background: color-mix(in srgb, var(--accent) 86%, black);
}

.secondary {
  background: var(--surface-2);
}

.notice {
  min-height: 1.5rem;
  margin: 0.6rem 0;
  color: var(--muted);
  font-size: 0.86rem;
  text-align: center;
}

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

.notice.success {
  color: #21865a;
}

.history {
  margin-top: 1.25rem;
}

.section-heading h2 {
  margin: 0;
  font-size: 0.95rem;
}

.selection-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 44px;
  margin-top: 0.55rem;
}

.select-all,
.clip-select {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  cursor: pointer;
}

.select-all {
  gap: 0.4rem;
}

.select-all input,
.clip-select input {
  width: 1.2rem;
  height: 1.2rem;
  min-height: 1.2rem;
  margin: 0;
  accent-color: var(--accent);
}

.selected-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.82rem;
}

.danger {
  border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
  color: var(--danger);
}

.empty {
  margin: 1.7rem 0;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.history-list {
  display: grid;
  gap: 0.7rem;
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
}

.clip-card {
  min-width: 0;
  padding: 0.9rem;
  box-shadow: none;
}

.clip-card.selected {
  border-color: color-mix(in srgb, var(--accent) 65%, var(--border));
}

.clip-body {
  min-width: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.clip-body a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.clip-image-button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
}

.clip-image-button:hover {
  background: transparent;
}

.clip-image {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 220px;
  border-radius: 11px;
  object-fit: contain;
}

.clip-image-button.expanded .clip-image {
  width: 100%;
  max-height: none;
}

.locked {
  color: var(--muted);
}

.unlock-button {
  margin-top: 0.6rem;
}

.clip-bottom {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.8rem;
}

.clip-meta {
  min-width: 0;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.clip-actions {
  flex: 0 0 auto;
  justify-content: flex-end;
  gap: 0.35rem;
}

.clip-select {
  width: 44px;
  flex: 0 0 44px;
}

.copy-button,
.delete-button {
  display: inline-grid;
  width: 44px;
  min-width: 44px;
  padding: 0;
  place-items: center;
  flex: 0 0 44px;
}

.clip-actions svg {
  width: 1.2rem;
  height: 1.2rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 480px) {
  .app {
    width: min(100% - 1.25rem, 760px);
    padding-top: max(0.75rem, env(safe-area-inset-top));
  }

  .room-row {
    align-items: stretch;
  }

  .room-code {
    flex: 1 1 9rem;
  }

  .top-actions {
    flex: 1 0 auto;
    justify-content: flex-end;
  }

  .composer {
    border-radius: 16px;
  }

  textarea {
    min-height: 9rem;
  }

  .composer-footer {
    align-items: flex-end;
  }

  #input-hint {
    max-width: 13rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
