:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", sans-serif;
  background: #f5f7fb;
  color: #1b2938;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.app-shell {
  width: min(960px, 100%);
  background: #ffffff;
  border-radius: 24px;
  box-shadow: 0 24px 60px rgba(45, 70, 96, 0.12);
  padding: 32px;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 2.5vw, 2.8rem);
  letter-spacing: -0.03em;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 24px;
}

.brand-logo {
  width: 220px;
  max-width: 50%;
  height: auto;
  object-fit: contain;
}

.mode-switch {
  display: inline-flex;
  gap: 0.5rem;
  border: 1px solid #d3dae8;
  border-radius: 999px;
  background: #f1f5fb;
  padding: 4px;
}

.mode-button {
  appearance: none;
  border: none;
  background: transparent;
  color: #425168;
  padding: 0.85rem 1.6rem;
  border-radius: 999px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.mode-button:hover {
  background: rgba(57, 119, 246, 0.08);
}

.mode-button.active {
  background: #3a7dfa;
  color: white;
  box-shadow: 0 10px 20px rgba(58, 125, 250, 0.18);
}

.key-field {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 0.5rem;
  margin-top: 24px;
  padding: 0.9rem 1rem;
  border-radius: 16px;
  background: #f7f9ff;
  border: 1px solid #e4eaf5;
}

.key-icon {
  font-size: 1.25rem;
}

.key-label {
  color: #55627c;
  font-weight: 600;
}

.key-field input {
  width: 100%;
  border: 1px solid #d7dde9;
  outline: none;
  background: #ffffff;
  padding: 0.75rem 0.95rem;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  color: #1b2938;
}

.message-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
  gap: 1rem;
  align-items: stretch;
  margin-top: 24px;
}

.message-block {
  display: grid;
  gap: 0.75rem;
  position: relative;
}

.message-block-wrapper {
  position: relative;
  display: grid;
}

.expand-btn {
  position: absolute;
  bottom: 0.75rem;
  right: 0.75rem;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 12px;
  border: 1px solid #a8c5ff;
  background: rgba(58, 125, 250, 0.12);
  color: #3a7dfa;
  font-size: 1.2rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.18s ease;
  z-index: 10;
}

.expand-btn:hover {
  background: rgba(58, 125, 250, 0.22);
  border-color: #3a7dfa;
}

.expand-btn:active {
  transform: scale(0.95);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(27, 41, 56, 0.92);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 1000;
}

.modal[hidden] {
  display: none;
}

.modal-content {
  position: relative;
  width: min(1000px, 95vw);
  height: min(600px, 85vh);
  background: #f8fbff;
  border-radius: 20px;
  padding: 2rem;
  display: grid;
  place-items: center;
  box-shadow: 0 40px 100px rgba(45, 70, 96, 0.25);
}

.modal-close {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  border-radius: 999px;
  background: #e8eef9;
  color: #2f436f;
  font-size: 1.8rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.18s ease, color 0.18s ease;
  z-index: 1001;
}

.modal-close:hover {
  background: #d7dfe9;
}

.modal-close:active {
  transform: scale(0.9);
}

.modal-text {
  font-size: 2.5rem;
  line-height: 1.8;
  color: #3a7dfa;
  word-break: break-word;
  text-align: center;
  max-height: 100%;
  overflow-y: auto;
  white-space: pre-wrap;
}

.message-block label {
  font-weight: 700;
  color: #303e5f;
}

.message-block textarea {
  width: 100%;
  min-height: 220px;
  resize: none;
  border: 1px solid #d7dde9;
  border-radius: 18px;
  padding: 1rem;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.6;
  color: #1b2938;
  background: #f8fbff;
}

.message-block textarea:focus {
  outline: 2px solid rgba(58, 125, 250, 0.35);
  border-color: #8ab4ff;
}

.message-block textarea[readonly] {
  background: #eef3ff;
  color: #425168;
}

.message-arrow {
  display: grid;
  place-items: center;
  font-size: clamp(3.2rem, 4vw, 4.5rem);
  color: #2f436f;
}

.wheel-row {
  margin-top: 32px;
  display: flex;
  justify-content: center;
}

.wheel {
  position: relative;
  width: min(420px, 100%);
  aspect-ratio: 1 / 1;
}

#wheelSvg {
  width: 100%;
  height: 100%;
  display: block;
}

.wheel-center {
  position: absolute;
  inset: 34%;
  border-radius: 50%;
  background: #0b0b0b;
  border: 2px solid #1f1f1f;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 0.8rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: #ffffff;
}

.wheel-segment {
  stroke: #ffffff;
  stroke-width: 1;
}

.wheel-label {
  font-family: inherit;
  font-weight: 800;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

.wheel-label.outer {
  fill: #ffffff;
  font-size: 1rem;
}

.wheel-label.inner {
  fill: #ffffff;
  font-size: 1rem;
}

.floating-tool {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: rgba(58, 125, 250, 0.12);
  border: 1px solid rgba(58, 125, 250, 0.28);
  box-shadow: 0 10px 25px rgba(45, 70, 96, 0.15);
  color: #2f436f;
  z-index: 1200;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  overflow: visible;
}

.floating-tool:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 30px rgba(45, 70, 96, 0.2);
}

.floating-tool-gear {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  pointer-events: none;
}

.floating-tool-key {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  z-index: 2;
  transform: translate(0, -1px);
  pointer-events: none;
}

/* Diffie-Hellman Key Generator Page */
.dh-container {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  gap: 0.8rem;
  align-items: center;
  justify-items: center;
  margin-top: calc(var(--blender-height) / 3);
  --blender-height: 60vh;
}

.dh-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
}

.dh-blender img {
  max-width: 100%;
  height: auto;
  max-height: var(--blender-height);
  display: block;
}

.dh-blender-vibrate {
  animation: dh-vibrate 0.75s ease-in-out 1;
  filter: drop-shadow(0 0 12px rgba(58, 125, 250, 0.7)) brightness(1.08);
}
@keyframes dh-vibrate {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  15% { transform: translateX(-8px) rotate(-5deg); }
  30% { transform: translateX(8px) rotate(5deg); }
  45% { transform: translateX(-6px) rotate(-4deg); }
  60% { transform: translateX(6px) rotate(4deg); }
  75% { transform: translateX(-4px) rotate(-2deg); }
  90% { transform: translateX(4px) rotate(2deg); }
}

.dh-keys {
  height: 100%;
  justify-content: space-around;
}

.dh-key-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0rem;
  cursor: pointer;
}

.dh-key {
  width: 180px;
  height: 180px;
  display: block;
  transform: scaleX(-1);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.dh-key-wrapper {
  position: relative;
  display: inline-block;
}

.dh-key-value {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.8rem;
  font-weight: 700;
  color: white;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.dh-key-red {
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.dh-key-yellow {
  color: #f39c12;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.dh-key-label {
  font-size: 1.15rem;
  font-weight: 600;
  color: #425168;
  text-transform: lowercase;
  margin-top: -1.15rem;
  line-height: 1;
}

.dh-error {
  min-height: 1.1rem;
  font-size: 0.7rem;
  color: #d32f2f;
  text-align: center;
  margin-top: 0.25rem;
  font-weight: 600;
}

.dh-number {
  gap: 0.75rem;
}

.dh-number input {
  width: 100%;
  min-width: 200px;
  padding: 0.75rem 1rem;
  border: 2px solid #d7dde9;
  border-radius: 12px;
  font-size: 1.8rem;
  font-weight: 700;
  color: #1b2938;
  background: #f8fbff;
  text-align: center;
  font-family: monospace;
}

.dh-number input:focus {
  outline: none;
  border-color: #3a7dfa;
  box-shadow: 0 0 0 3px rgba(58, 125, 250, 0.1);
}

.dh-number-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: #425168;
  text-transform: lowercase;
}

/* Key Input Modal */
.key-input-modal {
  position: fixed;
  inset: 0;
  background: rgba(27, 41, 56, 0.92);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 2000;
}

.key-input-modal[hidden] {
  display: none;
}

.key-input-modal-content {
  position: relative;
  background: #f8fbff;
  border-radius: 20px;
  padding: 2rem;
  width: min(400px, 90vw);
  box-shadow: 0 40px 100px rgba(45, 70, 96, 0.25);
}

.key-input-modal-content h2 {
  margin: 0 0 1.5rem 0;
  font-size: 1.3rem;
  color: #2f436f;
  text-align: center;
}

.key-input-modal-content input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid #d7dde9;
  border-radius: 12px;
  font-size: 1rem;
  margin-bottom: 1.5rem;
  box-sizing: border-box;
}

.key-input-modal-content input:focus {
  outline: none;
  border-color: #3a7dfa;
  box-shadow: 0 0 0 3px rgba(58, 125, 250, 0.1);
}

.key-input-submit {
  width: 100%;
  padding: 0.85rem 1.6rem;
  background: #3a7dfa;
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
}

.key-input-submit:hover {
  background: #2563dd;
}

.key-input-submit:active {
  transform: scale(0.98);
}

.key-input-modal .modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 50%;
  background: #e8eef9;
  color: #2f436f;
  font-size: 1.5rem;
  cursor: pointer;
  transition: background 0.18s ease;
}

.key-input-modal .modal-close:hover {
  background: #d7dfe9;
}

@media (max-width: 820px) {
  .message-row {
    grid-template-columns: 1fr;
  }

  .message-arrow {
    transform: rotate(90deg);
  }

  .dh-container {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}
