:root {
  --bg-1: #eef3f8;
  --bg-2: #d9e8f6;
  --text: #1b2430;
  --muted: #495668;
  --surface: #ffffff;
  --line: #c8d5e3;
  --accent: #0a6b5a;
  --accent-hover: #085748;
  --danger: #a81f2a;
  --success: #0b6a4d;
  --shadow-soft: 0 10px 24px rgba(17, 42, 67, 0.08);
  --shadow-strong: 0 20px 44px rgba(17, 42, 67, 0.12);
  --max: 1200px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", "Noto Sans", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 10% 10%, var(--bg-1), var(--bg-2));
}

body {
  line-height: 1.45;
  overflow-x: hidden;
}

.landing {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.layout {
  width: min(100%, var(--max));
  display: grid;
  grid-template-columns: 0.92fr 1.08fr;
  gap: clamp(1.25rem, 2vw, 2rem);
  align-items: center;
}

.left-col {
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: clamp(1.5rem, 2vw, 2.25rem);
  max-width: 640px;
  display: grid;
  gap: 1.15rem;
  box-shadow: var(--shadow-soft);
  min-width: 0;
  overflow-x: hidden;
}

.brand-mark {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #0d3443;
}

.eyebrow {
  margin: 0 0 0.6rem;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4.4vw, 3.5rem);
  line-height: 1.05;
}

.lead {
  margin: 0.35rem 0 0;
  color: #21333f;
  font-size: 1.1rem;
  max-width: 43ch;
}

.body-copy {
  margin: 0;
  color: var(--muted);
  max-width: 48ch;
}

.trust-copy {
  display: grid;
  gap: 0.35rem;
  padding: 1rem 1.05rem;
  border-radius: 16px;
  background: rgba(244, 249, 252, 0.92);
  border: 1px solid rgba(200, 213, 227, 0.85);
}

.trust-copy h2,
.choice-block h2,
.choice-card h3 {
  margin: 0;
}

.trust-copy p {
  margin: 0;
  color: var(--muted);
}

.choice-block {
  display: grid;
  gap: 0.9rem;
  margin-top: 0.25rem;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.choice-card {
  display: grid;
  gap: 0.7rem;
  padding: 1rem 1.05rem;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 10px 24px rgba(17, 42, 67, 0.05);
}

.choice-card-primary {
  background: linear-gradient(180deg, #f7fcf9, #eef8f3);
}

.choice-card-secondary {
  background: linear-gradient(180deg, #fbfcfe, #f3f6fa);
}

.choice-card p {
  margin: 0;
  color: var(--muted);
}

.choice-card-note {
  font-weight: 700;
  color: #0d3443;
}

.choice-icon {
  font-size: 0.9rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #0d3443;
}

.choice-card button {
  width: 100%;
}

.login-flow {
  display: grid;
  gap: 0.75rem;
  padding-top: 0.35rem;
}

.entry-status {
  margin: 0;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 0.75rem 0.9rem;
  background: #f8fbff;
  color: var(--muted);
}

.entry-status[data-state="pending"] {
  color: #1f5a8a;
}

.entry-status[data-state="success"] {
  color: var(--success);
}

.entry-status[data-state="error"] {
  color: var(--danger);
}

button {
  border: 0;
  border-radius: 12px;
  padding: 0.85rem 1.3rem;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

button:hover,
button:focus-visible {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.secondary-button {
  background: #546171;
}

.secondary-button:hover,
.secondary-button:focus-visible {
  background: #3f4a58;
}

.entry-panel {
  display: grid;
  gap: 0.65rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 0.9rem;
}

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

.entry-panel label {
  font-weight: 600;
}

.entry-row {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.entry-row input {
  flex: 1;
  min-width: 220px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem;
  font: inherit;
}

.entry-actions {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.right-col {
  position: relative;
  min-height: 520px;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.bestefar-stage {
  width: min(100%, 700px);
  aspect-ratio: 4 / 5;
  background: transparent;
  overflow: visible;
  position: relative;
}

.bestefar-stage-button {
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  z-index: 2;
}

.bestefar-stage-button:focus-visible {
  outline: 3px solid rgba(10, 107, 90, 0.35);
  outline-offset: 6px;
  border-radius: 18px;
}

.bestefar-image {
  width: 118%;
  height: auto;
  display: block;
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-44%);
  object-fit: contain;
  object-position: 58% 100%;
}

.trial-flow {
  width: min(100%, var(--max));
  margin-top: 0.25rem;
  display: grid;
  gap: 1rem;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

.trial-content {
  display: grid;
  gap: 1rem;
  min-width: 0;
  max-width: 100%;
}

.trial-step-container {
  display: grid;
  gap: 1rem;
  min-width: 0;
  max-width: 100%;
}

.trial-step {
  display: grid;
  min-width: 0;
  max-width: 100%;
}

.trial-step-body {
  min-width: 0;
  max-width: 100%;
}

.trial-flow[hidden] {
  display: none;
}

.trial-header,
.trial-stage {
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow-soft);
  min-width: 0;
  max-width: 100%;
}

.trial-header {
  padding: 1rem 1.1rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
}

.trial-kicker {
  margin: 0 0 0.35rem;
  color: #0d3443;
  font-size: 0.85rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.trial-header h2 {
  margin: 0;
  font-size: clamp(1.35rem, 2.5vw, 2rem);
  line-height: 1.08;
}

.trial-intro,
.trial-header-note,
.trial-hint,
.trial-status,
.trial-summary,
.trial-explanation {
  color: var(--muted);
}

.trial-header-note {
  max-width: 22rem;
  padding: 0.8rem 0.9rem;
  border-radius: 16px;
  background: rgba(244, 249, 252, 0.95);
  border: 1px solid rgba(200, 213, 227, 0.85);
}

.trial-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.trial-toolbar > * {
  min-height: 48px;
}

.trial-upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0.85rem 1.2rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.trial-upload-button input {
  display: none;
}

.trial-toolbar button {
  min-height: 48px;
}

.trial-stage {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(300px, 0.75fr);
  gap: 1rem;
  padding: 1rem;
  align-items: start;
}

.trial-stage > * {
  min-width: 0;
}

.trial-document-card,
.trial-inspector {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.8rem;
  min-width: 0;
  max-width: 100%;
}

.trial-document-status {
  margin: 0;
  font-weight: 700;
  color: #0d3443;
  min-height: 2.8rem;
  display: flex;
  align-items: center;
}

.trial-zoom-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
}

.trial-zoom-button {
  min-height: 44px;
  padding: 0.75rem 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
}

.trial-zoom-label {
  margin: 0;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--soft-ink);
  font-weight: 700;
  min-width: 5.5rem;
  text-align: center;
}

.trial-document-surface {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-height: 430px;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(180deg, #ffffff, #f3f7fb);
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.trial-document-viewport {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  border-radius: inherit;
  overscroll-behavior: contain;
}

.trial-document-surface[data-ready="false"] {
  display: grid;
  place-items: center;
}

.trial-document-surface[data-ready="true"] {
  display: block;
}

.trial-document-surface::before {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: 14px;
  border: 1px dashed rgba(73, 86, 104, 0.18);
}

#trialDocumentImage,
.trial-ring-layer,
.trial-ring {
  width: 100%;
  height: 100%;
}

#trialDocumentImage {
  position: relative;
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
  object-fit: contain;
  background: #fff;
  pointer-events: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.trial-ring-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  cursor: crosshair;
  pointer-events: auto;
  touch-action: pan-x pan-y pinch-zoom;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.trial-ring {
  position: absolute;
  inset: auto;
  z-index: 4;
  border: 3px solid rgba(10, 107, 90, 0.85);
  border-radius: 999px;
  background: rgba(10, 107, 90, 0.08);
  box-shadow: 0 0 0 6px rgba(10, 107, 90, 0.08);
}

.trial-hint {
  margin: 0;
  font-size: 0.95rem;
}

.trial-inspector {
  padding: 0.8rem;
  border: 1px solid rgba(200, 213, 227, 0.9);
  border-radius: 18px;
  background: rgba(244, 249, 252, 0.92);
  width: 100%;
  max-width: 100%;
  align-content: start;
  align-self: start;
  max-height: calc(100vh - 10rem);
  overflow: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.trial-inspector > * {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.trial-response-header {
  display: grid;
  gap: 0.35rem;
}

.trial-response-header h3,
.trial-response-header p,
.trial-response-copy .workspace-label {
  margin: 0;
}

.trial-response-header p {
  color: var(--muted);
}

.trial-response-copy {
  display: grid;
  gap: 0.4rem;
}

.trial-response-actions {
  display: flex;
  justify-content: flex-start;
  gap: 0.6rem;
}

.trial-response-actions button {
  min-height: 44px;
  padding: 0.7rem 1rem;
}

.trial-explanation {
  margin: 0;
  font-size: 1.04rem;
  color: #223042;
}

.trial-explanation,
.trial-summary,
.trial-status {
  margin: 0;
  width: 100%;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-all;
  overflow-x: hidden;
  white-space: pre-wrap;
  box-sizing: border-box;
}

.trial-actions {
  display: grid;
  gap: 0.55rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  min-width: 0;
  max-width: 100%;
}

.trial-toolbar button,
.trial-action,
.trial-question-row button,
.trial-question-actions button,
.trial-transition button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
  box-shadow: 0 8px 18px rgba(17, 42, 67, 0.08);
}

.trial-question-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.6rem;
  padding: 0.9rem;
  border: 1px solid rgba(200, 213, 227, 0.85);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.9);
}

.trial-question-panel label {
  font-weight: 700;
  color: #0d3443;
}

.trial-question-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
  max-width: 100%;
}

.trial-question-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem 0.9rem;
  font: inherit;
}

.trial-question-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.trial-action {
  background: #f7fbff;
  color: var(--soft-ink);
  border: 1px solid #d2e1eb;
}

.trial-action.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.trial-transition {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.45rem;
  padding: 0.9rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(200, 213, 227, 0.85);
}

.trial-transition p {
  margin: 0;
  width: 100%;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-all;
  overflow-x: hidden;
  box-sizing: border-box;
}

.trial-transition button {
  justify-self: start;
}

.trial-primary-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.6rem;
  margin-top: 0.25rem;
}

.trial-primary-actions .secondary-button {
  justify-self: start;
  min-width: 0;
}

.trial-primary-actions #trialSaveButton {
  width: 100%;
}

.trial-flow .secondary-button {
  background: #546171;
}

.trial-flow .secondary-button:hover,
.trial-flow .secondary-button:focus-visible {
  background: #3f4a58;
}

.trial-flow[data-mobile-mode="true"] .trial-ring-layer,
.trial-flow[data-mobile-mode="true"] .trial-hint {
  display: none;
}

.trial-flow[data-mobile-mode="true"] .trial-question-panel {
  display: grid;
}

.trial-flow[data-mobile-mode="true"] .trial-document-surface {
  min-height: 0;
  overflow: hidden;
}

.trial-flow[data-mobile-mode="true"] .trial-stage {
  align-items: start;
}

.trial-flow[data-mobile-mode="true"] .trial-inspector {
  max-height: min(46vh, 34rem);
}

.trial-flow[data-mobile-mode="true"] #trialDocumentImage {
  max-height: 100%;
}

.speech-bubble {
  position: absolute;
  top: 30%;
  left: 0.8rem;
  z-index: 1;
  max-width: 310px;
  background: #fff;
  border: 2px solid #bfd0e0;
  border-radius: 16px;
  padding: 1rem 1.1rem;
  color: #223042;
  box-shadow: var(--shadow-strong);
}

.speech-bubble::after {
  content: "";
  position: absolute;
  right: -11px;
  top: 28px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-right: 2px solid #bfd0e0;
  border-top: 2px solid #bfd0e0;
  transform: rotate(45deg);
}

@media (max-width: 900px) {
  .landing {
    place-items: start stretch;
    padding: 0.75rem;
  }

  .layout {
    width: 100%;
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
    align-items: start;
  }

  .left-col,
  .trial-flow,
  .trial-stage,
  .trial-document-card,
  .trial-inspector {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .left-col {
    max-width: none;
    padding: 1rem;
  }

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

  .right-col {
    position: static;
    display: grid;
    gap: 1rem;
    justify-items: center;
    min-height: 0;
    overflow: visible;
  }

  .bestefar-image {
    width: 100%;
    max-width: 420px;
    position: static;
    transform: none;
    object-position: center top;
  }

  .bestefar-stage {
    width: 100%;
    max-width: 420px;
    aspect-ratio: auto;
    overflow: visible;
  }

  .speech-bubble {
    position: static;
    margin-top: 0;
    width: 100%;
    max-width: 420px;
  }

  .speech-bubble::after {
    display: none;
  }

  .trial-header {
    flex-direction: column;
  }

  .trial-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .trial-zoom-controls {
    align-items: stretch;
  }

  .trial-zoom-button,
  .trial-zoom-label {
    width: 100%;
  }

  .trial-stage {
    grid-template-columns: minmax(0, 1fr);
  }

  .trial-inspector {
    max-height: min(42vh, 28rem);
  }

  .trial-actions {
    grid-template-columns: 1fr;
  }

  .trial-document-surface {
    min-height: 340px;
  }
}

@media (max-width: 600px) {
  body.trial-flow-open {
    overflow: hidden;
  }

  .trial-flow {
    margin-top: 0;
    position: fixed;
    inset: 0;
    z-index: 30;
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: radial-gradient(circle at 10% 10%, var(--bg-1), var(--bg-2));
    padding: 0.55rem;
  }

  .trial-header {
    flex: 0 0 auto;
    position: sticky;
    top: 0;
    z-index: 5;
    border-radius: 0;
  }

  .trial-header-note {
    display: none;
  }

  .trial-content {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
  }

  .trial-step-container {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: block;
  }

  .trial-step {
    display: none;
    height: 100%;
    min-height: 0;
  }

  .trial-flow[data-step="upload"] .trial-step[data-step="upload"] {
    display: grid;
  }

  .trial-flow[data-step="work"] .trial-step[data-step="work"] {
    display: grid;
  }

  .trial-step-body {
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .trial-flow[data-step="work"] .trial-step[data-step="work"] .trial-step-body {
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .trial-flow[data-step="work"] .trial-stage {
    min-height: 100%;
  }

}
