/* GLOBAL */
* { box-sizing: border-box; }
body {
  font-family: 'Trebuchet MS', 'Segoe UI', Arial, sans-serif;
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.28) 0 34px, transparent 35px),
    radial-gradient(circle at 78% 24%, rgba(255, 255, 255, 0.2) 0 58px, transparent 59px),
    radial-gradient(circle at 34% 78%, rgba(255, 255, 255, 0.18) 0 44px, transparent 45px),
    radial-gradient(circle at 92% 86%, rgba(255, 255, 255, 0.24) 0 72px, transparent 73px),
    linear-gradient(135deg, #b8d9f7 0%, #dceeff 52%, #a9c9eb 100%);
  margin: 0;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

.hidden { display: none; }

/* LOGIN PAGE */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: clamp(20px, 5vw, 56px); }
.login-card { position: relative; overflow: hidden; width: min(480px, 100%); min-height: 0; padding: 34px clamp(28px, 5vw, 44px) 36px; border: 1px solid rgba(255, 255, 255, 0.95); border-radius: 22px; background: rgba(255, 255, 255, 0.97); box-shadow: 0 22px 58px rgba(38, 84, 143, 0.2); }
.login-card::before { position: absolute; top: 0; right: 0; left: 0; height: 5px; background: linear-gradient(90deg, #173f78, #12a995); content: ''; }
.brand-inline { display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; }
.brand-logo { width: min(144px, 100%); height: auto; object-fit: contain; display: block; }
.login-badge { width: fit-content; margin: 0 auto 10px; padding: 6px 12px; border: 1px solid #d6e8f6; border-radius: 999px; background: #edf6fd; color: #22599b; font-size: 10px; font-weight: 800; letter-spacing: 1.2px; }
.app-title { text-align: center; font-family: 'Segoe UI', Arial, sans-serif; font-size: clamp(34px, 6vw, 42px); line-height: 1.1; color: #173f78; font-weight: 750; letter-spacing: -0.8px; margin: 0 0 8px; }
.app-sub { max-width: 42ch; text-align: center; font-size: 15px; line-height: 1.45; color: #5c7190; margin: 0 auto 16px; }
.passing-goal { display: flex; width: fit-content; align-items: center; gap: 10px; margin: 0 auto 20px; padding: 9px 14px; border: 1px solid #cfe8dc; border-radius: 999px; background: #f0faf4; color: #456255; font-size: 13px; }
.passing-goal strong { color: #17662e; font-size: 14px; }
.login-form { display: grid; gap: 14px; padding-top: 18px; border-top: 1px solid #e8eef5; }
.form-row { display: grid; grid-template-columns: 92px minmax(0, 1fr); align-items: center; gap: 12px; }
.form-label { font-weight: 650; font-size: 14px; color: #274568; }
.form-input { width: 100%; min-height: 50px; font-size: 16px; padding: 0 14px; border: 1px solid #cbd9e8; border-radius: 10px; outline: none; background: #fff; color: #183b68; transition: border-color .2s, box-shadow .2s; }
.form-input:focus { border-color: #2b80d7; box-shadow: 0 0 0 4px rgba(43, 128, 215, 0.14); }
.primary-btn { position: relative; display: flex; width: 100%; min-height: 54px; align-items: center; justify-content: center; margin-top: 4px; justify-self: stretch; padding: 12px 52px 12px 20px; border: 1px solid #123563; border-radius: 12px; background: linear-gradient(135deg, #24518b, #173f78); color: #fff; font-size: 16px; font-weight: 700; cursor: pointer; box-shadow: 0 5px 0 #0f315f, 0 10px 18px rgba(23, 63, 120, 0.18); transition: transform .18s ease, box-shadow .18s ease, background .18s ease; }
.button-arrow { position: absolute; right: 12px; display: grid; width: 32px; height: 32px; place-items: center; border-radius: 9px; background: rgba(255, 255, 255, 0.15); font-size: 21px; line-height: 1; transition: transform .18s ease, background .18s ease; }
.primary-btn:hover { transform: translateY(-2px); background: linear-gradient(135deg, #2a5d9d, #1a477f); box-shadow: 0 7px 0 #0f315f, 0 14px 22px rgba(23, 63, 120, 0.22); }
.primary-btn:hover .button-arrow { transform: translateX(2px); background: rgba(255, 255, 255, 0.23); }
.primary-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #0f315f, 0 4px 8px rgba(23, 63, 120, 0.16); }
.primary-btn:focus-visible { outline: 3px solid rgba(18, 169, 149, 0.45); outline-offset: 3px; }

/* MAIN LAYOUT */
.main-layout { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); gap: 24px; padding: 24px; max-width: 1720px; height: 100vh; height: 100dvh; margin: 0 auto; align-items: start; overflow: hidden; }
.container { min-height: 0; background: #fff; padding: 34px clamp(24px, 3vw, 42px) 30px; border: 1px solid rgba(255, 255, 255, 0.85); border-radius: 18px; max-width: none; margin: 0; width: 100%; box-shadow: 0 14px 36px rgba(43, 91, 150, 0.13); }
.container > h1 { text-align: center; margin: 0 0 22px; color: #173f78; font-size: clamp(30px, 2.3vw, 38px); letter-spacing: -0.5px; }
.right-panel { display: grid; grid-template-columns: minmax(300px, 0.8fr) minmax(0, 2.2fr); gap: 24px; align-items: stretch; align-self: stretch; width: 100%; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.displayText { display: none; }
.current { background-color: #fff3bf; border-bottom: 2px solid #0078D4; }

/* Typing shell (overlay + textarea) */
.typing-shell { position: relative; border: 1px solid #cbd9e8; border-radius: 14px; background: #fbfdff; height: 360px; overflow: hidden; box-shadow: inset 0 1px 3px rgba(28, 62, 100, 0.06); }
.typing-input,
.typing-overlay {
    font: 600 26px/1.65 'Segoe UI', 'Trebuchet MS', Arial, sans-serif;
    padding: 22px 24px;
    min-height: 360px;
    width: 100%;
    white-space: pre-wrap;
    overflow-wrap: normal;
    word-break: normal;
    hyphens: none;
}
.typing-input { position: relative; color: transparent; caret-color: transparent; background: transparent; border: 0; resize: none; outline: none; overflow: auto; }
.typing-overlay { position: absolute; top: 0; left: 0; right: 0; bottom: 0; pointer-events: none; color: #000; overflow: hidden; }
.typing-word { display: inline-block; white-space: nowrap; }
.correct { color: #243b53; font-weight: 600; }
.incorrect { color: #c43221; font-weight: 600; }
.untyped { color: #748397; font-weight: 600; }
.typing-caret {
  display: inline-block;
  height: 1.2em;
  margin-left: -1px;
  border-left: 2px solid #111;
  vertical-align: text-bottom;
  animation: typing-caret-blink 1s step-end infinite;
}
@keyframes typing-caret-blink {
  0%, 45% { opacity: 1; }
  46%, 100% { opacity: 0; }
}
@media (min-width: 1500px) {
  .typing-shell { height: 270px; }
  .typing-input,
  .typing-overlay { min-height: 270px; }
}
@media (min-width: 901px) and (max-height: 800px) {
  .main-layout { gap: 12px; padding: 12px 18px; }
  .container { padding: 18px 24px 16px; }
  .container > h1 { margin-bottom: 12px; font-size: clamp(26px, 2.2vw, 32px); }
  .typing-shell { height: clamp(200px, 34vh, 280px); }
  .typing-input,
  .typing-overlay { min-height: 0; }
}
.inline-stats { display: flex; justify-content: space-between; gap: 18px; font-size: 19px; font-weight: 600; color: #314760; margin: 18px 8px 12px; }
.button-group { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 16px; }
.big-btn { font-size: 18px; font-weight: 600; padding: 13px 20px; border-radius: 9px; cursor: pointer; }
#retakeBtn { background: #b9e8c5; border: 1px solid #79bd89; color: #174b26; }
#retakeBtn:hover { background: #a4ddb3; }
#newApplicantBtn { background: #ffe79a; border: 1px solid #d8b63e; color: #5b4700; }
#newApplicantBtn:hover { background: #ffdf73; }
#downloadBtn { background: #dcc7f5; border: 1px solid #ad8bd5; color: #45246e; }
#downloadBtn:hover { background: #ceb4ed; }
@media (min-width: 901px) and (max-height: 800px) {
  .inline-stats { font-size: 16px; margin: 12px 6px 8px; }
  .button-group { gap: 10px; margin-top: 10px; }
  .big-btn { padding: 10px 16px; font-size: 16px; }
}

/* Right results */
.result-card { background: #fff; border: 1px solid #e1e9f2; border-radius: 16px; padding: 28px; box-shadow: 0 8px 24px rgba(43, 91, 150, 0.1); font-family: 'Segoe UI', 'Trebuchet MS', Arial, sans-serif; }
.result-title { font-size: 27px; line-height: 1.25; font-weight: 750; color: #173f78; margin-bottom: 20px; }
.result-card.is-review .result-title { color: #1769a8; }
.result-line { font-size: 20px; margin: 14px 0; color: #314760; }
.result-line.blue { color: #106EBE; font-weight: 700; font-size: 21px; }

/* Completion result */
.result-modal { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 20px; background: rgba(15, 35, 60, 0.58); }
.result-modal[hidden] { display: none; }
body.result-modal-open .button-group { visibility: hidden; }
.result-dialog { width: min(440px, 100%); padding: 28px 24px 24px; border-radius: 22px; background: #fff; text-align: center; box-shadow: 0 24px 70px rgba(10, 34, 65, 0.3); }
.result-dialog h2 { margin: 0 0 20px; color: #173f78; font-size: 30px; }
.result-modal.is-review .result-dialog h2 { color: #1769a8; }
.result-score-circle { width: 230px; height: 230px; display: flex; flex-direction: column; align-items: center; justify-content: center; margin: 0 auto; border: 8px solid #f3b4b4; border-radius: 50%; background: #fde4e4; color: #a62222; }
.result-modal.is-passed .result-score-circle { border-color: #9bd4a8; background: #e0f5e5; color: #17662e; }
.result-modal.is-review .result-score-circle { border-color: #9bc9ef; background: #e2f2ff; color: #175f9f; }
.result-score { font-size: clamp(76px, 18vw, 102px); font-weight: 800; line-height: 0.95; }
.result-score-label { margin-top: 8px; font-size: 16px; font-weight: 700; }
.result-threshold { margin: 18px 0; color: #53657c; font-size: 16px; }
.result-save-message { margin: 0 0 16px; color: #a62222; font-size: 14px; line-height: 1.4; }
.result-action { min-width: 180px; border: 1px solid #d78383; border-radius: 9px; background: #f6d2d2; color: #782222; font-weight: 700; }
.result-action:hover { background: #efbebe; }
.result-modal.is-passed .result-action { border-color: #79bd89; background: #b9e8c5; color: #174b26; }
.result-modal.is-passed .result-action:hover { background: #a4ddb3; }
.result-modal.is-review .result-action { border-color: #8dbde5; background: #d7ebff; color: #174e7a; }
.result-modal.is-review .result-action:hover { background: #c4e1fb; }

/* History */
.history-panel { display: flex; min-width: 0; min-height: 0; flex-direction: column; overflow: hidden; background: #fff; border: 1px solid #e1e9f2; border-radius: 16px; padding: 26px 28px; box-shadow: 0 8px 24px rgba(43, 91, 150, 0.1); font-family: 'Segoe UI', 'Trebuchet MS', Arial, sans-serif; }
.history-panel h2 { font-size: 25px; line-height: 1.3; color: #173f78; text-align: center; margin: 2px 0 20px; }
.history-table-wrap { flex: 1; min-height: 0; max-height: none; overflow-y: auto; overflow-x: auto; }
.history-table { width: 100%; min-width: 0; border-collapse: separate; border-spacing: 0; font-size: 15px; text-align: center; table-layout: fixed; }
.history-table th, .history-table td { border-right: 1px solid #d8e3f0; border-bottom: 1px solid #d8e3f0; padding: 13px 10px; white-space: nowrap; }
.history-table th:first-child, .history-table td:first-child { border-left: 1px solid #d8e3f0; }
.history-table thead th { border-top: 1px solid #d8e3f0; }
.history-table th { position: sticky; top: 0; background: #dceeff; color: #173f78; z-index: 1; }
.history-table td { background: #f8fbff; }
.history-table th:first-child, .history-table td:first-child { width: 6%; }
.history-table th:nth-child(2), .history-table td:nth-child(2) { width: 20%; }
.history-table th:nth-child(3), .history-table td:nth-child(3) { width: 12%; }
.history-table th:nth-child(4), .history-table td:nth-child(4) { width: 11%; }
.history-table th:nth-child(5), .history-table td:nth-child(5) { width: 12%; }
.history-table th:nth-child(6), .history-table td:nth-child(6) { width: 15%; }
.history-table th:nth-child(7), .history-table td:nth-child(7) { width: 10%; }
.history-table th:last-child, .history-table td:last-child { width: 14%; }

@media (max-width: 900px) {
  .main-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 12px;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: visible;
    padding: 12px;
  }

  .right-panel {
    order: 2;
    grid-template-columns: 1fr;
    gap: 16px;
    min-height: 0;
    overflow: visible;
  }

  .history-panel {
    display: block;
    min-height: 220px;
    overflow: visible;
  }

  .history-table-wrap {
    flex: none;
    max-height: none;
    overflow-y: visible;
  }

  .container {
    padding: 18px 16px 14px;
  }

  .typing-shell {
    height: clamp(180px, 36vh, 340px);
    min-height: 0;
    overflow: hidden;
  }

  .typing-input,
  .typing-overlay {
    min-height: 0;
  }

  .displayText {
    font-size: 20px;
    line-height: 1.5;
  }

  .typing-overlay {
    font-size: 20px;
    line-height: 1.5;
  }

  .typing-input {
    font-size: 20px;
    line-height: 1.5;
  }

  .typing-overlay {
    position: absolute;
    inset: 0;
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .typing-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: auto;
    z-index: 1;
    caret-color: transparent;
  }

  .typing-overlay {
    z-index: 2;
  }

  .inline-stats {
    font-size: 16px;
    flex-wrap: wrap;
    gap: 10px 18px;
    margin: 16px 4px 10px;
  }

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

  .big-btn {
    width: 100%;
  }

  .result-dialog { padding: 24px 18px 20px; }
  .result-dialog h2 { font-size: 26px; }
  .result-score-circle { width: 200px; height: 200px; }
}

@media (max-width: 600px) {
  .history-panel {
    padding: 20px 16px;
    min-width: 0;
  }

  .history-panel h2 {
    font-size: 22px;
    margin-bottom: 10px;
  }

  .history-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: auto;
  }

  .history-table {
    width: 100%;
    min-width: 650px;
    font-size: 13px;
  }

  .history-table th,
  .history-table td {
    padding: 9px 8px;
    white-space: nowrap;
  }

  .login-page { min-height: 100dvh; padding: 12px 16px; }

  .login-card {
    width: 100%;
    max-width: 440px;
    padding: 18px 24px 20px;
    border-radius: 18px;
  }

  .brand-inline { margin-bottom: 10px; }
  .brand-logo { width: 126px; }
  .login-badge { margin-bottom: 7px; padding: 5px 10px; font-size: 9px; }

  .app-title {
    font-size: 34px;
    margin-bottom: 5px;
  }

  .app-sub {
    font-size: 13px;
    line-height: 1.35;
    margin-bottom: 10px;
  }

  .passing-goal { margin-bottom: 12px; padding: 7px 11px; font-size: 12px; }
  .passing-goal strong { font-size: 13px; }

  .login-form {
    gap: 8px;
    padding-top: 12px;
  }

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

  .form-label {
    font-size: 13px;
  }

  .form-input {
    font-size: 15px;
    min-height: 44px;
  }

  .primary-btn {
    width: 100%;
    font-size: 15px;
    min-height: 48px;
  }
}
