#new_game_container {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  padding: 26px 24px 40px;
  background: #f7f9fc;

  .new_game_header {
    width: 100%;
    max-width: 940px;
    margin: 0 auto 18px;

    .page_title {
      margin: 0 0 4px;
      color: #263746;
    }

    p {
      margin: 0;
      color: #647181;
      line-height: 1.5;
    }
  }

  #game_sort_and_filter {
    box-sizing: border-box;
    width: 100%;
    max-width: 940px;
    margin: 0 auto 16px;
    padding: 12px 14px;
    border: 1px solid #d8e0e8;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 1px 4px rgba(25, 48, 68, 0.04);

    .filter {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      gap: 6px;
      padding: 0;

      .filter_link, .clear {
        box-sizing: border-box;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 34px;
        min-height: 34px;
        margin: 0;
        padding: 5px 7px;
        border: 1px solid #d8e0e8;
        border-radius: 7px;
        background: #f8fafc;
      }

      .filter_link {
        float: none;
        opacity: 0.5;

        &.selected {
          border-color: #78bddd;
          background: #eaf6fc;
          opacity: 1;
        }
      }

      .clear {
        color: #647181;
        font-size: 18px;
        line-height: 1;
      }
    }

    .sort {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      top: 12px;
      right: 14px;
      height: 34px;

      .sort_link {
        box-sizing: border-box;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 34px;
        float: none;
        margin-left: 6px;
        padding: 8px 10px;
        border: 1px solid #d8e0e8;
        border-radius: 7px;
        background: #f8fafc;
        color: #526171;

        &.selected {
          border-color: #78bddd;
          background: #eaf6fc;
          color: #176b96;
        }
      }
    }
  }

  .game_and_submit {
    box-sizing: border-box;
    width: 100%;
    max-width: 940px;
    margin: 0 auto;
    flex-grow: 1;
    align-items: center;
  }

  .new_game {
    position: relative;
    min-width: 0;
    margin: 0;
    text-align: center;

    #game {
      box-sizing: border-box;
      min-width: 0;
      padding: 18px;
      border: 1px solid #d8e0e8;
      border-radius: 12px;
      background: #fff;
      box-shadow: 0 2px 8px rgba(25, 48, 68, 0.05);
    }

    .modes {
      display: grid;
      grid-template-columns: minmax(0, 2fr) minmax(220px, 1fr);
      align-items: start;
      justify-content: center;
      gap: 12px;
      margin-top: 12px;
    }

    .options, .opponent {
      box-sizing: border-box;
      width: auto;
      min-width: 0;
      margin: 0;
      padding: 14px;
      border: 1px solid #d8e0e8;
      border-radius: 12px;
      background: #fff;
      box-shadow: 0 2px 8px rgba(25, 48, 68, 0.05);

      h2 {
        margin: 0 0 3px;
        padding: 0;
        color: #263746;
        font-size: 18px;
      }

      .section_hint {
        margin: 0 0 10px;
        color: #647181;
        font-size: 13px;
        line-height: 1.4;
      }

      ul {
        overflow: auto;
        max-height: 300px;
        border: 1px solid #d8e0e8;
        border-radius: 8px;
        background: #f8fafc;
      }
    }

    .options {
      text-align: left;

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

      .mode_count {
        padding: 3px 8px;
        border-radius: 6px;
        background: #eef5fa;
        color: #176b96;
        font-size: 12px;
        font-weight: 600;
        font-variant-numeric: tabular-nums;
      }

      .mode_limit_status {
        margin: 0 0 10px;
        padding: 8px 10px;
        border: 1px solid #e6b8b2;
        border-left: 3px solid #bf4b3d;
        border-radius: 8px;
        background: #fff3f1;
        color: #91382e;
        font-size: 13px;
        line-height: 1.4;

        &:empty { display: none; }
      }

      .features {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: start;
        gap: 6px;
        max-height: none;
        overflow: visible;
        margin: 0;
        padding: 0;
        border: 0;
        background: transparent;
        list-style: none;
      }

      .features .feature {
        min-width: 0;
        border: 1px solid #d8e0e8;
        border-radius: 8px;
        background: #f8fafc;
        color: #34475a;
        font: inherit;
        line-height: normal;
        overflow: hidden;
        cursor: default;
        transition: border-color 120ms, background 120ms;

        &:first-child { border: 1px solid #d8e0e8; }
        &:hover { background: #eef7fc; }

        &.selected {
          border-color: #78bddd;
          background: #eef8fd;
          color: #176b96;
        }

        &.unavailable {
          border-color: #e4e9ef;
          background: #f5f7f9;
          color: #7c8997;

          .icon { opacity: 0.4; }
          .mode_check { color: #b6c0ca; }
        }

        .mode_toggle {
          box-sizing: border-box;
          display: flex;
          align-items: center;
          gap: 7px;
          width: 100%;
          min-height: 38px;
          margin: 0;
          padding: 6px 9px;
          border: 0;
          background: transparent;
          color: inherit;
          font: 600 13px/1.3 Arial, sans-serif;
          text-align: left;
          cursor: pointer;

          &:disabled { cursor: not-allowed; }
          &:focus-visible {
            outline: 2px solid #176b96;
            outline-offset: -3px;
            border-radius: 7px;
          }
        }

        .icon { float: none; flex-shrink: 0; }
        .mode_name { flex: 1; }
        .mode_check { font-size: 16px; color: #648499; }
        &.selected .mode_check { color: #176b96; }

        .choices {
          display: none;
          grid-template-columns: repeat(4, minmax(0, 1fr));
          gap: 4px;
          padding: 0 8px 8px;

          .choice {
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: center;
            gap: 2px;
            min-width: 0;
            min-height: 30px;
            height: auto;
            padding: 4px 2px;
            border: 1px solid #d8e0e8;
            border-radius: 5px;
            background: #fff;
            color: #526171;
            font: 12px/1.2 Arial, sans-serif;
            cursor: pointer;

            &:hover { border-color: #78bddd; background: #eef7fc; }
            &:focus-visible { outline: 2px solid #176b96; outline-offset: 1px; }
            &.selected { border-color: #78bddd; background: #ccecfb; color: #176b96; }
            &.locked { color: #7c8997; }
            .icon { width: 12px; height: 12px; }
            .operator { font-size: 10px; }
          }

          .mode_description {
            grid-column: 1 / -1;
            margin: 2px 0 0;
            padding: 0;
            color: #586979;
            font: 11px/1.4 Arial, sans-serif;
          }
        }

        &.selected .choices { display: grid; }
      }
    }

    .opponent {
      text-align: left;

      .opponent_choices {
        display: grid;
        gap: 6px;
        max-height: 244px;
        margin: 0;
        padding: 0 3px 0 0;
        border: 0;
        border-radius: 0;
        background: transparent;
        list-style: none;
        scrollbar-width: thin;
        scrollbar-color: #c4d0dc transparent;

        li { min-width: 0; }
      }

      .friend {
        box-sizing: border-box;
        position: relative;
        display: flex;
        align-items: center;
        gap: 9px;
        width: 100%;
        min-height: 42px;
        margin: 0;
        padding: 7px 10px;
        border: 1px solid #d8e0e8;
        border-radius: 8px;
        background: #f8fafc;
        color: #34475a;
        font: 600 13px/1.3 Arial, sans-serif;
        text-align: left;
        cursor: pointer;
        transition: background 120ms, border-color 120ms;

        &:hover {
          border-color: #b2cddd;
          background: #eef7fc;
        }

        &:focus-visible {
          outline: 2px solid #176b96;
          outline-offset: -3px;
        }

        .avatar {
          flex-shrink: 0;
          float: none;
          width: 28px;
          height: 28px;
          margin: 0;
          border-radius: 7px;
          line-height: 28px;
          color: #7c8997;
        }

        .random_opponent_avatar {
          display: flex;
          align-items: center;
          justify-content: center;
          background: #eaf2f8;
        }

        .online {
          top: 4px;
          left: 30px;
          padding: 1px;
          border-radius: 50%;
          background: #fff;
          font-size: 10px;
        }

        .opponent_name { flex: 1; min-width: 0; }

        .username {
          display: block;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }

        .opponent_detail {
          display: block;
          margin-top: 2px;
          color: #647181;
          font-size: 11px;
          font-weight: 400;
        }

        .opponent_check {
          box-sizing: border-box;
          flex-shrink: 0;
          width: 15px;
          height: 15px;
          border: 1px solid #bdcad5;
          border-radius: 50%;
          background: #fff;
        }

        &.selected {
          border-color: #78bddd;
          background: #eef8fd;
          color: #176b96;

          .opponent_check {
            border: 4px solid #176b96;
          }
        }
      }
    }

    .submit_area {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 12px;
      margin: 16px auto 0;

      .dict {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        margin: 0;
        padding: 9px 12px;
        border: 1px solid #d8e0e8;
        border-radius: 8px;
        background: #fff;
        font-family: 'Acme';

        label {
          margin: 0;
          color: #34475a;
          font-size: 17px;
        }

        select {
          appearance: none;
          padding: 5px 30px 5px 9px;
          border: 1px solid #bdcad5;
          border-radius: 6px;
          background: #fff;
          background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='m1 1 4 4 4-4' fill='none' stroke='%23526171' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
          background-repeat: no-repeat;
          background-position: right 10px center;
          color: #263746;
        }
      }

      .submit .btn_link {
        padding: 10px 18px;
        border: 1px solid #1686bb;
        border-radius: 8px;
        background: var(--btn-primary);
        color: #08354d;

        &:hover, &:focus-visible {
          border-color: #0874aa;
          background: #18a7e8;
        }

        &:focus-visible {
          outline: 2px solid #176b96;
          outline-offset: 2px;
        }

        &:disabled {
          border-color: #d8e0e8;
          background: #eef2f5;
          color: #647181;
          cursor: default;
        }
      }
    }
  }
}

@media (max-width: 700px) {
  #new_game_container {
    .new_game .modes {
      grid-template-columns: minmax(0, 1fr);
    }

    #game_sort_and_filter .sort {
      position: static;
      display: flex;
      flex-wrap: wrap;
      justify-content: flex-start;
      gap: 6px;
      height: auto;
      margin-top: 10px;

      .sort_link {
        margin: 0;
      }
    }
  }
}

@media (max-width: 480px) {
  #new_game_container {
    padding: 20px 12px 32px;

    .new_game_header {
      margin-bottom: 14px;

      .page_title {
        font-size: 28px;
      }
    }

    #game_sort_and_filter {
      padding: 10px;

      .sort {
        gap: 5px;
        margin-top: 8px;
      }
    }

    .new_game {
      #game {
        padding: 12px 10px;
      }

      .options, .opponent {
        padding: 12px;
      }

      .options .features {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
      }

      .submit_area {
        align-items: stretch;
        flex-direction: column;

        .dict {
          justify-content: center;
        }

        .submit .btn_link {
          width: 100%;
        }
      }
    }
  }
}
