@media (max-width: 900px) {
  .app {
    width: 100%;
    max-width: 100%;
  }

  .chat-log {
    height: 44vh;
  }
}

@media (max-width: 760px) {
  :root {
    --sp-gap: 12px;
  }

  body {
    display: block;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 0;
  }

  .bg-orb {
    width: 180px;
    height: 180px;
    filter: blur(30px);
  }

  .app {
    height: 100vh;
    height: 100dvh;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    border-width: 2px;
    box-shadow: 4px 4px 0 var(--neon);
    padding:
      calc(10px + env(safe-area-inset-top, 0px))
      12px
      calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .app-header {
    gap: 10px;
    padding-bottom: 10px;
    border-bottom-width: 2px;
    flex-shrink: 0;
  }

  .kicker {
    font-size: 0.62rem;
    letter-spacing: 0.12em;
  }

  .app-header h1 {
    font-size: clamp(1rem, 5.5vw, 1.32rem);
    line-height: 1.25;
  }

  .subtitle {
    font-size: 0.82rem;
  }

  .screen {
    margin-top: 14px;
    padding: 12px;
    min-height: 0;
  }

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

  #screen-top.active #join-btn {
    margin-top: auto;
  }

  #screen-waiting.active {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  #screen-waiting.active #waiting-title,
  #screen-waiting.active #waiting-text,
  #screen-waiting.active #countdown {
    width: 100%;
    text-align: center;
  }

  #screen-waiting.active .spinner {
    margin-left: auto;
    margin-right: auto;
  }

  #screen-chat.active {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    overflow: hidden;
  }

  .screen h2 {
    font-size: 1rem;
  }

  .screen p {
    font-size: 0.92rem;
  }

  .chat-meta {
    gap: var(--sp-gap);
    margin-bottom: var(--sp-gap);
  }

  .chat-status {
    gap: 4px;
  }

  #status-text {
    font-size: 0.86rem;
  }

  #session-countdown {
    font-size: 0.85rem;
  }

  #screen-chat.active .chat-meta {
    flex-shrink: 0;
  }

  #screen-chat.active .chat-log {
    min-height: 0;
    height: auto;
    padding: 10px;
    border-width: 1px;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  #screen-chat.active .chat-form {
    flex-shrink: 0;
    margin-top: var(--sp-gap);
    position: sticky;
    bottom: 0;
    z-index: 2;
    padding-top: 8px;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px));
    background:
      linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0),
        rgba(0, 0, 0, 0.78) 26%,
        rgba(0, 0, 0, 0.92)
      );
  }

  .message {
    padding: 8px;
    border-width: 1px;
    margin-bottom: 9px;
  }

  .message-role {
    font-size: 0.64rem;
  }

  .message-text {
    margin-top: 6px;
    font-size: 0.92rem;
    line-height: 1.35;
  }

  .guess-actions-message .message-text-row {
    gap: 8px;
    flex-wrap: wrap;
  }

  .guess-actions-message .chat-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .chat-form {
    gap: 8px;
  }

  .chat-form input {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 16px;
  }

  button,
  .guess-btn,
  .chat-form button {
    min-height: 42px;
    padding: 9px 12px;
    font-size: 0.82rem;
  }

  #result-text {
    font-size: 0.98rem;
    margin-bottom: 12px;
    padding: 10px;
  }

  #result-rematch-btn,
  #result-top-btn {
    margin-top: 6px;
  }
}

@media (max-width: 420px) {
  body {
    padding-left: 8px;
    padding-right: 8px;
  }

  .app {
    padding: 10px;
  }

  .screen {
    padding: 10px;
  }

  #screen-chat.active .chat-log {
    min-height: 0;
  }

  .guess-actions-message .chat-actions {
    justify-content: stretch;
  }

  .guess-actions-message .guess-btn {
    flex: 1;
    min-width: 0;
  }
}
