:root {
      --bg: #e6f7f5;
      --primary: #27a89b;
      --primary-dark: #1d7d74;
      --accent: #22b8cf;
      --text: #033b3a;
      --error: #d9534f;
      --heart-red: #e53935;
      --heart-grey: #b0bec5;
      --card-bg: #ffffff;
    }

    * {
      box-sizing: border-box;
      font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    }

    body {
      margin: 0;
      background: radial-gradient(circle at top, #c6f4ee 0, var(--bg) 40%, #d0f0ea 100%);
      color: var(--text);
      height: 100vh;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    #app {
      width: 100%;
      max-width: 900px;
      height: 90vh;
      max-height: 600px;
      background: var(--card-bg);
      border-radius: 18px;
      box-shadow: 0 16px 40px rgba(0, 0, 0, 0.12);
      padding: 20px 24px;
      display: flex;
      flex-direction: column;
      position: relative;
      overflow: hidden;
    }

    h1, h2, h3 {
      margin: 0;
      font-weight: 600;
    }

    button {
      border: none;
      border-radius: 999px;
      padding: 8px 16px;
      cursor: pointer;
      font-size: 14px;
      transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.1s ease;
    }

    button:active {
      transform: translateY(1px);
      box-shadow: none;
    }

    .btn-primary {
      background: linear-gradient(135deg, var(--primary), var(--accent));
      color: white;
      box-shadow: 0 6px 14px rgba(0, 150, 136, 0.4);
    }

    .btn-primary:hover {
      background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    }

    .btn-secondary {
      background: #e0f2f1;
      color: var(--primary-dark);
    }

    .btn-danger {
      background: var(--error);
      color: #fff;
    }

    textarea, input[type="text"], select {
      width: 100%;
      border-radius: 10px;
      border: 1px solid #cfd8dc;
      padding: 10px 12px;
      font-size: 14px;
      outline: none;
      transition: border 0.15s ease, box-shadow 0.15s ease;
      background: #f9fbfb;
    }

    textarea {
      resize: vertical;
      min-height: 48px;
    }

    textarea:focus, input[type="text"]:focus, select:focus {
      border-color: var(--accent);
      box-shadow: 0 0 0 2px rgba(34, 184, 207, 0.25);
      background: #ffffff;
    }

    .small-hint {
      font-size: 12px;
      color: #607d8b;
      margin-top: 6px;
      white-space: pre-line;
    }

    .screen {
      display: none;
      flex: 1;
      margin-top: 10px;
      position: relative;
    }

    .screen.active {
      display: flex;
      flex-direction: column;
    }

    .centered {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      text-align: center;
      flex: 1;
    }

    .top-bar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 12px;
      gap: 8px;
    }

    .top-left, .top-right, .top-center {
      display: flex;
      align-items: center;
    }

    .top-center {
      flex: 1;
      justify-content: center;
    }

    .mode-toggle {
      display: inline-flex;
      background: #e0f7f5;
      border-radius: 999px;
      padding: 3px;
      gap: 4px;
    }

    .mode-btn {
      font-size: 12px;
      padding: 4px 10px;
      border-radius: 999px;
      background: transparent;
      color: var(--primary-dark);
      cursor: pointer;
      border: none;
    }

    .mode-btn.active {
      background: #ffffff;
      color: var(--primary-dark);
      box-shadow: 0 1px 4px rgba(0,0,0,0.12);
    }

    .score-box {
      background: #e0f2f1;
      border-radius: 999px;
      padding: 6px 12px;
      font-size: 12px;
      display: flex;
      flex-direction: column;
      align-items: flex-end;
      min-width: 90px;
    }

    .score-main {
      font-weight: 600;
      font-size: 14px;
    }

    .score-sub {
      font-size: 11px;
      color: #455a64;
    }

    .hearts {
      display: flex;
      align-items: center;
      gap: 3px;
    }

    .heart {
      font-size: 18px;
      color: var(--heart-red);
      text-shadow: 0 0 4px rgba(229, 57, 53, 0.4);
    }

    .heart.lost {
      color: var(--heart-grey);
      text-shadow: none;
    }

    .question-container {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      gap: 16px;
    }

    .question-card {
      min-width: 60%;
      max-width: 80%;
      padding: 20px 24px;
      border-radius: 16px;
      background: linear-gradient(145deg, #e0f7f5, #ffffff);
      box-shadow: 0 10px 25px rgba(0,0,0,0.08);
      text-align: center;
    }

    .question-label {
      font-size: 13px;
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: #607d8b;
      margin-bottom: 6px;
    }

    .question-text {
      font-size: 20px;
      font-weight: 600;
      color: var(--primary-dark);
      word-wrap: break-word;
    }

    .answer-area {
      width: 60%;
      max-width: 460px;
      min-width: 260px;
    }

    .feedback {
      margin-top: 6px;
      font-size: 13px;
      min-height: 18px;
    }

    .feedback.correct {
      color: #2e7d32;
    }

    .feedback.wrong {
      color: var(--error);
    }

    .bottom-bar {
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-size: 12px;
      color: #607d8b;
      margin-top: 8px;
    }

    .saved-indicator {
      position: absolute;
      bottom: 8px;
      left: 10px;
      font-size: 10px;
      color: #546e7a;
      opacity: 0;
      transition: opacity 0.3s ease;
    }

    .saved-indicator.visible {
      opacity: 1;
    }

    .waiting-bar {
      width: 60%;
      max-width: 400px;
      height: 8px;
      border-radius: 999px;
      background: #e0f2f1;
      overflow: hidden;
      margin-top: 16px;
    }

    .waiting-fill {
      height: 100%;
      width: 0%;
      background: linear-gradient(90deg, var(--primary), var(--accent));
      transition: width 0.4s ease;
    }

    .overlay-dim {
      position: absolute;
      inset: 0;
      background: rgba(0, 0, 0, 0.35);
      display: none;
      align-items: center;
      justify-content: center;
      z-index: 10;
    }

    .overlay-dim.active {
      display: flex;
    }

    .popup {
      background: #ffffff;
      border-radius: 16px;
      padding: 20px 22px;
      width: 320px;
      max-width: 90%;
      box-shadow: 0 14px 32px rgba(0,0,0,0.3);
      text-align: center;
    }

    .popup h2 {
      margin-bottom: 6px;
    }

    .popup-scores {
      font-size: 14px;
      margin: 10px 0 16px;
    }

    .popup-buttons {
      display: flex;
      justify-content: center;
      gap: 10px;
      margin-top: 8px;
      flex-wrap: wrap;
    }

    .error-text {
      color: var(--error);
      font-size: 12px;
      margin-top: 6px;
      min-height: 16px;
    }

    .brand-title {
      font-weight: 700;
      letter-spacing: 0.08em;
      font-size: 11px;
      text-transform: uppercase;
      color: #607d8b;
    }

    .saved-sets-row {
      display: flex;
      gap: 8px;
      margin-top: 10px;
      align-items: center;
      flex-wrap: wrap;
    }

    .saved-sets-row select {
      max-width: 260px;
    }

    @media (max-width: 640px) {
      #app {
        height: 100vh;
        max-height: none;
        border-radius: 0;
      }
      .question-card {
        min-width: 80%;
      }
      .answer-area {
        width: 80%;
      }
      .top-bar {
        flex-wrap: wrap;
      }
      .top-center {
        order: 2;
        margin-top: 6px;
      }
    }