@layer reset, tokens, base, layout, components, states, responsive;

@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  * {
    margin: 0;
  }

  button,
  input,
  select {
    font: inherit;
  }
}

@layer tokens {
  :root {
    color-scheme: dark;
    --color-bg: #070b13;
    --color-surface: #0d1420;
    --color-surface-raised: #121b29;
    --color-border: #243044;
    --color-border-soft: #1a2637;
    --color-text: #f4f7fb;
    --color-muted: #8f9caf;
    --color-subtle: #606e82;
    --color-primary: #ffcf4a;
    --color-primary-dark: #dcae28;
    --color-primary-soft: rgb(255 207 74 / 12%);
    --color-correct: #3ddc97;
    --color-correct-soft: rgb(61 220 151 / 12%);
    --color-wrong: #ff6978;
    --color-wrong-soft: rgb(255 105 120 / 12%);
    --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 22px;
    --shadow-panel: 0 24px 70px rgb(0 0 0 / 24%);
    --transition-fast: 160ms ease;
  }
}

@layer base {
  html {
    min-width: 320px;
    background: var(--color-bg);
  }

  body {
    min-height: 100vh;
    color: var(--color-text);
    background:
      radial-gradient(circle at 18% 0%, rgb(255 207 74 / 5%), transparent 28rem),
      var(--color-bg);
    font-family: var(--font-sans);
    line-height: 1.5;
  }

  button,
  select {
    cursor: pointer;
  }

  button:focus-visible,
  input:focus-visible,
  select:focus-visible {
    outline: 3px solid rgb(255 207 74 / 28%);
    outline-offset: 2px;
  }

  button:disabled,
  input:disabled,
  select:disabled {
    cursor: not-allowed;
    opacity: 0.55;
  }

  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

@layer layout {
  .app-shell {
    width: min(1480px, 100%);
    min-height: 100vh;
    margin-inline: auto;
    padding: 0 36px 36px;
  }

  .topbar {
    display: flex;
    min-height: 96px;
    align-items: center;
    justify-content: space-between;
    gap: 32px;
    border-bottom: 1px solid var(--color-border-soft);
  }

  .game-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(310px, 380px);
    min-height: calc(100vh - 132px);
  }

  .game-panel {
    padding: 54px clamp(20px, 5vw, 82px) 30px 0;
  }

  .sidebar {
    display: flex;
    min-height: 100%;
    flex-direction: column;
    padding: 54px 0 30px 38px;
    border-left: 1px solid var(--color-border-soft);
  }
}

@layer components {
  .brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: var(--color-text);
    text-decoration: none;
  }

  .brand__mark {
    display: grid;
    width: 44px;
    height: 44px;
    place-items: center;
    color: #111722;
    background: var(--color-primary);
    border-radius: 12px;
    box-shadow: 0 8px 28px rgb(255 207 74 / 18%);
    font-size: 1.4rem;
    font-weight: 900;
  }

  .brand strong,
  .brand small {
    display: block;
  }

  .brand strong {
    letter-spacing: 0.16em;
  }

  .brand small {
    color: var(--color-muted);
    font-size: 0.72rem;
    letter-spacing: 0.04em;
  }

  .profile-summary {
    display: flex;
    align-items: center;
    gap: 22px;
  }

  .profile-summary__identity {
    display: flex;
    align-items: center;
    gap: 11px;
  }

  .profile-summary__identity strong,
  .profile-summary__identity span {
    display: block;
  }

  .profile-summary__identity strong {
    font-size: 0.9rem;
  }

  .profile-summary__identity span {
    color: var(--color-primary);
    font-size: 0.72rem;
    font-weight: 700;
  }

  .avatar {
    display: block;
    flex: 0 0 auto;
    background:
      linear-gradient(145deg, rgb(255 207 74 / 14%), rgb(49 95 169 / 10%)),
      #101927;
    border: 1px solid rgb(255 207 74 / 24%);
    border-radius: 50%;
    image-rendering: pixelated;
  }

  .avatar--header {
    width: 42px;
    height: 42px;
  }

  .avatar--large {
    width: 72px;
    height: 72px;
  }

  .level-progress {
    width: 210px;
  }

  .level-progress__labels,
  .timer-area__labels {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .level-progress__labels {
    margin-bottom: 7px;
    color: var(--color-muted);
    font-size: 0.72rem;
  }

  .level-progress__labels strong {
    color: var(--color-text);
  }

  .progress-track {
    overflow: hidden;
    background: #1b2533;
    border-radius: 999px;
  }

  .progress-track > span {
    display: block;
    width: 0;
    height: 100%;
    background: var(--color-primary);
    border-radius: inherit;
    transition: width 220ms linear;
  }

  .progress-track--xp {
    height: 5px;
  }

  .progress-track--timer {
    height: 9px;
  }

  .progress-track--timer > span {
    width: 100%;
  }

  .icon-button {
    display: grid;
    width: 42px;
    height: 42px;
    padding: 10px;
    place-items: center;
    color: var(--color-muted);
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    transition: color var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
  }

  .icon-button:hover {
    color: var(--color-text);
    background: var(--color-surface-raised);
    border-color: #3b485d;
  }

  .icon-button svg {
    width: 100%;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.7;
  }

  .game-panel__header,
  .sidebar__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
  }

  .eyebrow {
    display: block;
    margin-bottom: 8px;
    color: var(--color-primary);
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.18em;
  }

  h1 {
    max-width: 650px;
    font-size: clamp(1.7rem, 3vw, 2.65rem);
    line-height: 1.15;
    letter-spacing: -0.035em;
  }

  h2 {
    font-size: 1.05rem;
  }

  .streak-badge {
    display: grid;
    grid-template-columns: auto auto;
    align-items: center;
    column-gap: 7px;
    min-width: 112px;
    padding: 9px 14px;
    background: var(--color-primary-soft);
    border: 1px solid rgb(255 207 74 / 20%);
    border-radius: 11px;
  }

  .streak-badge svg {
    grid-row: span 2;
    width: 22px;
    fill: var(--color-primary);
  }

  .streak-badge strong {
    color: var(--color-primary);
    font-size: 1rem;
  }

  .streak-badge span {
    color: var(--color-muted);
    font-size: 0.62rem;
  }

  .game-controls {
    display: flex;
    gap: 14px;
    margin: 34px 0 18px;
  }

  .control-field {
    display: grid;
    min-width: 210px;
    gap: 6px;
  }

  .control-field > span,
  .profile-name-field > span {
    color: var(--color-muted);
    font-size: 0.72rem;
    font-weight: 700;
  }

  select,
  .profile-name-field input,
  .onboarding-name input {
    min-height: 44px;
    padding: 0 13px;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
  }

  select:hover {
    border-color: #3b485d;
  }

  .challenge {
    position: relative;
    min-height: 396px;
    padding: clamp(24px, 4vw, 44px);
    background:
      linear-gradient(145deg, rgb(255 255 255 / 1.5%), transparent 40%),
      var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-panel);
  }

  .challenge__status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    color: var(--color-muted);
    font-size: 0.75rem;
  }

  .difficulty-pill {
    padding: 5px 10px;
    color: var(--color-primary);
    background: var(--color-primary-soft);
    border: 1px solid rgb(255 207 74 / 20%);
    border-radius: 999px;
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.12em;
  }

  .challenge__content {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(190px, 0.75fr);
    align-items: start;
    gap: clamp(18px, 3vw, 38px);
    margin: 54px 0 32px;
  }

  .expression {
    display: flex;
    min-height: 68px;
    align-items: center;
    justify-content: flex-end;
    font-family: var(--font-mono);
    font-size: clamp(2rem, 5vw, 4rem);
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.06em;
    white-space: nowrap;
  }

  .expression__placeholder {
    color: var(--color-subtle);
  }

  .equals-sign {
    color: var(--color-subtle);
    font-family: var(--font-mono);
    font-size: clamp(2rem, 4vw, 3rem);
    font-weight: 300;
    line-height: 1.35;
  }

  .answer-form {
    display: grid;
    grid-template-columns: minmax(120px, 1fr);
    gap: 10px;
  }

  .answer-form input {
    width: 100%;
    min-height: 66px;
    padding: 0 18px;
    color: var(--color-text);
    background: #080d15;
    border: 2px solid var(--color-border);
    border-radius: 11px;
    font-family: var(--font-mono);
    font-size: clamp(1.25rem, 3vw, 2rem);
    font-weight: 700;
    text-align: center;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  }

  .answer-form input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 4px rgb(255 207 74 / 8%);
    outline: none;
  }

  .answer-form small {
    color: var(--color-subtle);
    font-size: 0.66rem;
    text-align: center;
  }

  .button {
    min-height: 43px;
    padding: 0 18px;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    font-weight: 800;
    transition: transform var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast);
  }

  .button:active:not(:disabled) {
    transform: translateY(1px);
  }

  .button--primary,
  .button--start {
    color: #111722;
    background: var(--color-primary);
    border: 1px solid var(--color-primary);
  }

  .button--primary:hover,
  .button--start:hover {
    background: #ffda70;
  }

  .button--secondary {
    color: var(--color-text);
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
  }

  .button--secondary:hover {
    border-color: #46546a;
  }

  .button--danger {
    color: white;
    background: #d94757;
    border: 1px solid #d94757;
  }

  .button--start {
    display: flex;
    min-width: 190px;
    margin: 30px auto 0;
    align-items: center;
    justify-content: center;
    gap: 9px;
  }

  .feedback {
    min-height: 24px;
    margin: -15px 0 15px;
    color: var(--color-muted);
    font-size: 0.8rem;
    font-weight: 700;
    text-align: center;
  }

  .timer-area {
    max-width: 660px;
    margin-inline: auto;
  }

  .timer-area__labels {
    margin-bottom: 10px;
    color: var(--color-muted);
    font-size: 0.75rem;
  }

  .timer-area__labels strong {
    color: var(--color-primary);
    font-family: var(--font-mono);
    font-size: 0.9rem;
  }

  .session-stats {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(22px, 5vw, 68px);
    padding-top: 25px;
    color: var(--color-muted);
    font-size: 0.78rem;
  }

  .session-stats > div {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .session-stats strong {
    color: var(--color-text);
  }

  .session-stats__icon {
    color: var(--color-muted);
    font-size: 1.05rem;
  }

  .session-stats__icon--correct {
    color: var(--color-correct);
  }

  .session-stats__icon--wrong {
    color: var(--color-wrong);
  }

  .text-button {
    padding: 4px;
    color: var(--color-muted);
    background: transparent;
    border: 0;
    font-size: 0.72rem;
    font-weight: 700;
  }

  .text-button:hover {
    color: var(--color-text);
  }

  .text-button--danger {
    color: var(--color-wrong);
  }

  .activity-log {
    display: flex;
    min-height: 300px;
    max-height: calc(100vh - 315px);
    flex-direction: column;
    gap: 9px;
    margin-top: 28px;
    padding: 0 7px 0 0;
    overflow-y: auto;
    list-style: none;
    scrollbar-color: var(--color-border) transparent;
    scrollbar-width: thin;
  }

  .activity-log__empty {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 15px;
    color: var(--color-subtle);
    text-align: center;
  }

  .activity-log__empty > span {
    margin-bottom: 12px;
    color: var(--color-border);
    font-family: Georgia, serif;
    font-size: 3rem;
  }

  .activity-log__empty strong {
    margin-bottom: 4px;
    color: var(--color-muted);
    font-size: 0.8rem;
  }

  .activity-log__empty small {
    max-width: 220px;
    font-size: 0.68rem;
  }

  .log-entry {
    display: grid;
    grid-template-columns: 31px minmax(0, 1fr) auto;
    gap: 10px;
    padding: 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border-soft);
    border-radius: 10px;
    animation: slide-in 220ms ease-out;
  }

  .log-entry__icon {
    display: grid;
    width: 31px;
    height: 31px;
    place-items: center;
    border-radius: 8px;
    font-weight: 900;
  }

  .log-entry--correct .log-entry__icon {
    color: var(--color-correct);
    background: var(--color-correct-soft);
  }

  .log-entry--wrong .log-entry__icon,
  .log-entry--timeout .log-entry__icon {
    color: var(--color-wrong);
    background: var(--color-wrong-soft);
  }

  .log-entry--level .log-entry__icon {
    color: var(--color-primary);
    background: var(--color-primary-soft);
  }

  .log-entry__main {
    min-width: 0;
  }

  .log-entry__main strong,
  .log-entry__main span {
    display: block;
  }

  .log-entry__main strong {
    overflow: hidden;
    font-family: var(--font-mono);
    font-size: 0.77rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .log-entry__main span,
  .log-entry__meta {
    color: var(--color-muted);
    font-size: 0.64rem;
  }

  .log-entry__meta {
    text-align: right;
  }

  .log-entry__meta strong {
    display: block;
    color: var(--color-primary);
    font-size: 0.67rem;
  }

  .sidebar__tip {
    display: flex;
    gap: 10px;
    margin-top: auto;
    padding: 16px;
    color: var(--color-muted);
    background: rgb(255 207 74 / 4%);
    border: 1px solid rgb(255 207 74 / 10%);
    border-radius: 10px;
    font-size: 0.68rem;
  }

  .sidebar__tip > span {
    color: var(--color-primary);
    font-size: 1.15rem;
  }

  .sidebar__tip strong {
    color: var(--color-text);
  }

  dialog {
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    box-shadow: 0 30px 100px rgb(0 0 0 / 55%);
  }

  dialog::backdrop {
    background: rgb(2 5 10 / 78%);
    backdrop-filter: blur(4px);
  }

  .profile-dialog {
    width: min(760px, calc(100% - 30px));
    max-height: calc(100vh - 30px);
    margin: auto;
    padding: 28px;
    overflow-y: auto;
    border-radius: var(--radius-lg);
  }

  .dialog-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
  }

  .dialog-header .icon-button {
    font-size: 1.4rem;
  }

  .profile-card {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 15px;
    padding: 18px;
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border-soft);
    border-radius: var(--radius-md);
  }

  .profile-name-field {
    display: grid;
    gap: 6px;
  }

  .profile-dialog__save {
    display: block;
    width: 100%;
    margin: 14px 0 16px;
  }

  .avatar-editor {
    display: grid;
    grid-template-columns: 210px minmax(0, 1fr);
    gap: 22px;
    margin-top: 16px;
    padding: 20px;
    background: #090f18;
    border: 1px solid var(--color-border-soft);
    border-radius: var(--radius-md);
  }

  .avatar-editor__preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 0;
    text-align: center;
  }

  .avatar-editor__preview h3 {
    font-size: 0.9rem;
  }

  .pixel-avatar {
    display: block;
    background:
      linear-gradient(45deg, rgb(255 255 255 / 2%) 25%, transparent 25% 75%, rgb(255 255 255 / 2%) 75%),
      linear-gradient(45deg, rgb(255 255 255 / 2%) 25%, transparent 25% 75%, rgb(255 255 255 / 2%) 75%),
      radial-gradient(circle, rgb(255 207 74 / 11%), transparent 67%),
      var(--color-surface);
    background-position: 0 0, 6px 6px, 0 0, 0 0;
    background-size: 12px 12px, 12px 12px, auto, auto;
    border: 1px solid var(--color-border);
    border-radius: 16px;
    image-rendering: pixelated;
  }

  .pixel-avatar--editor {
    width: 160px;
    height: 160px;
    margin-top: 15px;
  }

  .pixel-avatar--onboarding {
    width: 192px;
    height: 192px;
    margin-top: 15px;
  }

  .avatar-editor__controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: center;
    gap: 15px 18px;
  }

  .avatar-field {
    display: grid;
    gap: 6px;
  }

  .avatar-field > span,
  .avatar-palette legend,
  .onboarding-name > span {
    color: var(--color-muted);
    font-size: 0.7rem;
    font-weight: 700;
  }

  .avatar-field select {
    width: 100%;
  }

  .avatar-palette {
    min-width: 0;
    padding: 0;
    border: 0;
  }

  .avatar-palette legend {
    margin-bottom: 7px;
  }

  .avatar-palette > div {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
  }

  .color-swatch {
    position: relative;
    width: 29px;
    height: 29px;
    padding: 0;
    background: var(--swatch-color);
    border: 2px solid #111927;
    border-radius: 8px;
    box-shadow: 0 0 0 1px var(--color-border);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  }

  .color-swatch:hover {
    transform: translateY(-1px);
  }

  .color-swatch[aria-pressed="true"] {
    box-shadow: 0 0 0 2px var(--color-primary);
  }

  .color-swatch[aria-pressed="true"]::after {
    position: absolute;
    right: -4px;
    bottom: -4px;
    display: grid;
    width: 13px;
    height: 13px;
    place-items: center;
    color: #111722;
    background: var(--color-primary);
    border-radius: 50%;
    content: "✓";
    font-size: 0.55rem;
    font-weight: 900;
  }

  .onboarding-dialog {
    width: min(820px, calc(100% - 30px));
    max-height: calc(100vh - 30px);
    margin: auto;
    padding: 30px;
    overflow-y: auto;
    border-radius: var(--radius-lg);
  }

  .onboarding-dialog__intro {
    display: grid;
    justify-items: center;
    text-align: center;
  }

  .onboarding-dialog__intro .brand__mark {
    margin-bottom: 16px;
  }

  .onboarding-dialog__intro h2 {
    font-size: clamp(1.5rem, 4vw, 2.2rem);
    letter-spacing: -0.03em;
  }

  .onboarding-dialog__intro p {
    max-width: 460px;
    margin-top: 7px;
    color: var(--color-muted);
    font-size: 0.8rem;
  }

  .onboarding-name {
    display: grid;
    max-width: 430px;
    gap: 7px;
    margin: 24px auto 0;
  }

  .onboarding-name input {
    width: 100%;
    font-size: 1rem;
    text-align: center;
  }

  .avatar-editor--onboarding {
    grid-template-columns: 230px minmax(0, 1fr);
  }

  .onboarding-dialog__submit {
    display: block;
    min-width: 240px;
    margin: 3px auto 0;
  }

  .rank-card {
    display: flex;
    align-items: center;
    gap: 17px;
    margin: 16px 0;
    padding: 17px 18px;
    background: var(--color-primary-soft);
    border: 1px solid rgb(255 207 74 / 18%);
    border-radius: var(--radius-md);
  }

  .rank-card__level {
    padding-right: 17px;
    color: var(--color-primary);
    border-right: 1px solid rgb(255 207 74 / 18%);
    font-size: 0.66rem;
    font-weight: 800;
  }

  .rank-card__level strong {
    display: block;
    font-size: 1.4rem;
  }

  .rank-card > div strong,
  .rank-card > div span {
    display: block;
  }

  .rank-card > div span {
    color: var(--color-muted);
    font-size: 0.68rem;
  }

  .stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }

  .stats-grid > div {
    padding: 16px;
    background: #090f18;
    border: 1px solid var(--color-border-soft);
    border-radius: 10px;
  }

  .stats-grid span,
  .stats-grid strong {
    display: block;
  }

  .stats-grid span {
    color: var(--color-muted);
    font-size: 0.66rem;
  }

  .stats-grid strong {
    margin-top: 4px;
    font-size: 1.12rem;
  }

  .data-tools {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-top: 16px;
    padding: 18px;
    border: 1px solid var(--color-border-soft);
    border-radius: var(--radius-md);
  }

  .data-tools h3 {
    font-size: 0.86rem;
  }

  .data-tools p {
    max-width: 260px;
    margin-top: 4px;
    color: var(--color-muted);
    font-size: 0.66rem;
  }

  .data-tools__actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
  }

  .dialog-message {
    min-height: 21px;
    margin-top: 10px;
    color: var(--color-correct);
    font-size: 0.72rem;
    text-align: center;
  }

  .confirm-dialog {
    width: min(430px, calc(100% - 30px));
    margin: auto;
    padding: 26px;
    border-radius: var(--radius-lg);
  }

  .confirm-dialog p {
    margin: 10px 0 24px;
    color: var(--color-muted);
    font-size: 0.82rem;
  }

  .confirm-dialog__actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
  }

  .toast {
    position: fixed;
    z-index: 20;
    right: 24px;
    bottom: 24px;
    max-width: min(370px, calc(100% - 48px));
    padding: 13px 17px;
    color: var(--color-text);
    background: #172131;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    box-shadow: 0 14px 50px rgb(0 0 0 / 35%);
    font-size: 0.76rem;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: opacity var(--transition-fast), transform var(--transition-fast);
  }

  .toast.is-visible {
    opacity: 1;
    transform: translateY(0);
  }

  @keyframes slide-in {
    from {
      opacity: 0;
      transform: translateX(12px);
    }
  }
}

@layer states {
  .challenge[data-state="correct"] {
    border-color: rgb(61 220 151 / 42%);
  }

  .challenge[data-state="wrong"] {
    border-color: rgb(255 105 120 / 42%);
  }

  .challenge[data-state="correct"] .feedback {
    color: var(--color-correct);
  }

  .challenge[data-state="wrong"] .feedback {
    color: var(--color-wrong);
  }

  .progress-track--timer.is-warning > span {
    background: #ff9e4a;
  }

  .progress-track--timer.is-danger > span {
    background: var(--color-wrong);
  }
}

@layer responsive {
  @media (max-width: 950px) {
    .app-shell {
      padding-inline: 22px;
    }

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

    .game-panel {
      padding-right: 0;
    }

    .sidebar {
      min-height: auto;
      padding: 34px 0 10px;
      border-top: 1px solid var(--color-border-soft);
      border-left: 0;
    }

    .activity-log {
      max-height: 440px;
    }

    .sidebar__tip {
      margin-top: 25px;
    }
  }

  @media (max-width: 680px) {
    .app-shell {
      padding: 0 15px 25px;
    }

    .topbar {
      min-height: 78px;
    }

    .profile-summary__identity,
    .level-progress {
      display: none;
    }

    .game-panel {
      padding-top: 35px;
    }

    .game-panel__header {
      align-items: flex-end;
    }

    .streak-badge {
      min-width: auto;
    }

    .streak-badge span {
      display: none;
    }

    .game-controls {
      display: grid;
      grid-template-columns: 1fr 1fr;
      margin-top: 27px;
    }

    .control-field {
      min-width: 0;
    }

    .control-field select {
      width: 100%;
      font-size: 0.76rem;
    }

    .challenge {
      min-height: 0;
      padding: 22px 18px 26px;
    }

    .challenge__content {
      grid-template-columns: minmax(0, 1fr) auto minmax(120px, 1fr);
      gap: 12px;
      margin: 45px 0 31px;
    }

    .expression {
      min-height: 58px;
      font-size: clamp(1.65rem, 8vw, 2.5rem);
    }

    .equals-sign {
      font-size: 1.9rem;
    }

    .answer-form input {
      min-height: 58px;
      padding-inline: 9px;
      font-size: 1.2rem;
    }

    .answer-form .button {
      padding-inline: 10px;
      font-size: 0.69rem;
    }

    .answer-form small {
      display: none;
    }

    .session-stats {
      justify-content: space-between;
      gap: 8px;
    }

    .profile-card {
      grid-template-columns: auto 1fr;
      align-items: center;
    }

    .avatar-editor,
    .avatar-editor--onboarding {
      grid-template-columns: 1fr;
    }

    .pixel-avatar--onboarding {
      width: 160px;
      height: 160px;
    }

    .stats-grid {
      grid-template-columns: repeat(2, 1fr);
    }

    .data-tools {
      align-items: stretch;
      flex-direction: column;
    }

    .data-tools__actions {
      justify-content: flex-start;
    }
  }

  @media (max-width: 440px) {
    .brand small {
      display: none;
    }

    .game-controls {
      grid-template-columns: 1fr;
    }

    .challenge__content {
      grid-template-columns: 1fr auto;
      margin-top: 35px;
    }

    .expression {
      justify-content: center;
    }

    .answer-form {
      grid-column: 1 / -1;
    }

    .equals-sign {
      display: none;
    }

    .session-stats > div {
      align-items: center;
      flex-direction: column;
      gap: 2px;
      text-align: center;
    }

    .profile-dialog,
    .onboarding-dialog {
      padding: 21px 16px;
    }

    .avatar-editor {
      padding: 16px;
    }

    .avatar-editor__controls {
      grid-template-columns: 1fr;
    }

    .profile-card {
      grid-template-columns: 1fr;
      justify-items: center;
    }

    .profile-name-field {
      width: 100%;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      scroll-behavior: auto;
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }
}
