:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #16202a;
  --muted: #5f6f81;
  --line: #d9e0e8;
  --alice: #0f766e;
  --server: #b45309;
  --bob: #2563eb;
  --danger: #b91c1c;
  --success: #15803d;
  --cipher: #263241;
  --shadow: 0 18px 45px rgba(25, 35, 51, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  min-height: 42px;
  padding: 10px 14px;
}

button:hover {
  border-color: #99a8b8;
}

.site-header {
  max-width: 1220px;
  margin: 0 auto;
  padding: 24px 20px 14px;
  text-align: center;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin: 0 0 8px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(1.8rem, 4vw, 2.75rem);
  line-height: 1.05;
  margin-bottom: 18px;
}

main {
  max-width: 1220px;
  margin: 0 auto;
  padding: 0 20px 42px;
}

.mode-card {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin: 0 auto;
  max-width: 760px;
  padding: 12px;
}

.mode-toggle {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: 100%;
}

.mode-button.active {
  background: #172033;
  border-color: #172033;
  color: white;
}

.warning,
.security-section,
.explain-section,
.comparison-section,
.keys-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin: 18px 0;
  padding: 18px;
}

.warning {
  border-left: 6px solid var(--server);
}

.panels {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
  padding: 18px;
}

.alice-panel {
  border-top: 6px solid var(--alice);
}

.server-panel {
  border-top: 6px solid var(--server);
}

.bob-panel {
  border-top: 6px solid var(--bob);
}

.panel-heading,
.block-title-row {
  align-items: flex-start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.panel h2 {
  font-size: 1.3rem;
  margin-bottom: 4px;
}

.panel-heading p {
  color: var(--muted);
  margin-bottom: 16px;
}

.badge {
  border-radius: 999px;
  color: white;
  font-size: 0.72rem;
  font-weight: 900;
  padding: 5px 9px;
  white-space: nowrap;
}

.alice-badge {
  background: var(--alice);
}

.server-badge {
  background: var(--server);
}

.bob-badge {
  background: var(--bob);
}

label {
  color: var(--muted);
  display: block;
  font-weight: 800;
  margin-bottom: 8px;
}

textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 138px;
  padding: 12px;
  resize: vertical;
  width: 100%;
}

input {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
  min-height: 42px;
  padding: 10px 12px;
  width: 100%;
}

.primary-button {
  background: #172033;
  border-color: #172033;
  color: white;
  margin-top: 12px;
  width: 100%;
}

.secondary-button {
  min-height: 34px;
  padding: 7px 10px;
}

.danger-button {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}

.data-block {
  margin-top: 16px;
}

.important {
  background: #fff8ed;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  padding: 12px;
}

.data-block h3,
.comparison-card h3,
.key-card h3 {
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
  text-transform: uppercase;
}

pre {
  background: #f0f4f8;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0;
  max-height: 240px;
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.ciphertext,
.json-output,
.key-output {
  background: var(--cipher);
  color: #dbeafe;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem;
}

.plaintext {
  background: #eefdf4;
  color: #14532d;
}

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

.status-message {
  border-radius: 8px;
  font-weight: 900;
  margin: 10px 0 0;
  padding: 10px;
}

.status-message.readable {
  background: #fee2e2;
  color: #991b1b;
}

.status-message.protected {
  background: #dcfce7;
  color: #14532d;
}

.status-message.neutral {
  background: #edf2f7;
  color: #334155;
}

.button-row {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
  margin-top: 12px;
}

.result-box {
  border-radius: 8px;
  font-weight: 800;
  margin-top: 12px;
  padding: 12px;
}

.result-box.success {
  background: #dcfce7;
  color: #14532d;
}

.result-box.failure {
  background: #fee2e2;
  color: #991b1b;
}

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

.log-entry {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.log-meta {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  margin-bottom: 6px;
}

.decrypt-step {
  animation: pulse 1s ease-in-out infinite;
  background: #dbeafe;
  border-radius: 8px;
  color: #1e3a8a;
  font-weight: 900;
  margin-top: 12px;
  padding: 12px;
}

@keyframes pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.keys-grid,
.comparison-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 12px;
}

.key-card,
.comparison-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

summary {
  cursor: pointer;
  font-weight: 900;
}

.small-note {
  color: var(--muted);
  font-size: 0.86rem;
  margin-bottom: 8px;
}

.emphasis {
  color: var(--danger);
  font-weight: 900;
  margin-bottom: 0;
}

blockquote {
  border-left: 4px solid var(--bob);
  margin: 0 0 12px;
  padding-left: 12px;
}

.reset-row {
  display: flex;
  justify-content: center;
  margin: 24px 0 0;
}

.hidden {
  display: none !important;
}

.compact-header {
  padding-bottom: 6px;
}

.header-link a {
  color: var(--bob);
  font-weight: 900;
}

.join-panel {
  margin: 18px 0;
}

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

.chat-layout {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
}

.chat-layout.single-chat {
  grid-template-columns: 1fr;
}

.room-strip {
  background: #eef6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: 180px 1fr;
  margin-bottom: 14px;
  padding: 12px;
}

.room-strip strong,
.room-strip span {
  display: block;
}

.room-strip span {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.chat-messages {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
  min-height: 320px;
  max-height: min(52vh, 520px);
  overflow: auto;
  padding: 12px;
}

.chat-message {
  max-width: min(78%, 620px);
}

.chat-message.mine {
  align-self: flex-end;
}

.chat-message.theirs {
  align-self: flex-start;
}

.chat-meta {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.chat-body {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.mine .chat-body {
  background: #e6fffb;
  border-color: #99f6e4;
}

.cipher-preview {
  background: var(--cipher);
  color: #dbeafe;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.mode-error {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
  font-family: inherit;
  font-style: italic;
  font-weight: 400;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: normal;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.admin-grid {
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.4fr) minmax(260px, 0.9fr);
}

.admin-message-button {
  align-items: stretch;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 0;
  text-align: left;
  width: 100%;
}

.admin-message-button span {
  color: var(--muted);
  font-size: 0.8rem;
}

.admin-message-button code {
  color: var(--text);
  overflow-wrap: anywhere;
  white-space: normal;
}

.result-box.neutral {
  background: #edf2f7;
  color: #334155;
}

.send-explain {
  margin-top: 14px;
}

.site-footer {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  padding: 8px 20px 28px;
  text-align: center;
}

@media (max-width: 960px) {
  .panels,
  .keys-grid,
  .comparison-grid,
  .chat-layout,
  .join-grid {
    grid-template-columns: 1fr;
  }

}

@media (max-width: 700px) {
  .room-strip {
    grid-template-columns: 1fr;
  }

  .chat-message {
    max-width: 100%;
  }
}

@media (max-width: 560px) {
  main,
  .site-header {
    padding-left: 12px;
    padding-right: 12px;
  }

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

  .mode-card {
    display: flex;
    width: 100%;
  }

  .mode-toggle,
  .mode-button {
    width: 100%;
  }

  .mode-toggle {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 14px;
  }

  .chat-messages {
    max-height: 50vh;
    min-height: 300px;
  }

  textarea {
    min-height: 96px;
  }
}
