/* =============== Modal (nested, optimized, scoped-responsive) =============== */

.modal {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 0; /* opened via .modal-on .modal.on */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;

  z-index: 150;
  .modal-popup {
    border-radius: 20px;
    h1 {
      font-size: 1.75em;
      font-weight: 800;
      line-height: 1.3;
    }
    .contents.legal {
      padding-top: 0;
    }
    &.cert h1.certificated {
      color: var(--main);
      display: flex;
      align-items: center;
      &::after {
        content: '인증완료';
        color: #fff;
        font-size: 0.5em;
        background-color: var(--main);
        border-radius: 5px;
        padding: 9px 12px;
        display: inline-block;
        margin-left: 10px;
        line-height: 1;
        animation: certok 1s linear infinite;
        transform-origin: center;
      }
    }
    h2 {
      color: var(--gray-mid);
      font-size: 1em;
      font-weight: normal;
      span {
        font-weight: bold;
        color: var(--main);
      }
    }
    .info {
      padding: 1.5em;
      background-color: var(--gray-pale);
      border-radius: 12px;
      margin-top: 20px;
      text-align: center;
      &.login-form {
        padding: var(--padding);
      }
      .tab-content & {
        margin-top: 0;
      }
      h5 {
        color: var(--gray-mid);
      }
      h2 {
        font-weight: bold;
        font-size: 1.8em;
        color: var(--gray-dark);
      }
    }
  }
  &.on {
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(30px);
    transform: translateZ(0); /* 또는 transform: translate3d(0, 0, 0); */
    -webkit-transform: translateZ(0); /* 웹킷 접두사 */
    backface-visibility: hidden; /* 추가적인 안정성 확보 */
    -webkit-backface-visibility: hidden;
    perspective: 1000;
    -webkit-perspective: 1000;
  }

  &.system {
    z-index: 160;
    text-align: center;
  }

  .dimed {
    position: absolute;
    inset: 0;
    z-index: 1;
    background-color: rgba(0, 0, 0, 0.6);
    transition: background 0.25s;
    opacity: 0;
  }

  .modal-popup {
    position: relative;
    z-index: 2;
    max-width: 90%;
    max-height: 90%;
    overflow: hidden;

    box-shadow: 60px 60px 90px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    &:has(.calendar) {
      width: 100%;
      max-width: var(--width);
    }

    .popup-content {
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      overscroll-behavior: contain;
      display: flex;
      flex-direction: column;
      border-radius: 20px 20px 0 0;
      background-color: #fff;
      line-height: 1.5;
      flex-grow: 0;
      max-height: calc(100% - var(--btn-h));

      .head {
        padding: var(--padding);
      }
      &.split {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        width: max-content;
      }

      > li {
        padding: 24px;
        border-bottom: 1px solid #ddd;
        &:last-of-type {
          border-bottom: 0;
        }
      }

      .descript .img-set {
        overflow: hidden;

        margin: 20px 0;
        display: flex;
        gap: 10px;
        img {
          height: var(--btn-h);
        }
      }

      .grid {
        &:not(:first-child) {
          margin-top: var(--padding);
        }
        table {
          th {
            white-space: nowrap;
          }
          .canceled {
            text-decoration: line-through;
          }
          td:has(.button) {
            padding: 10px;
          }
          .button {
            border-color: var(--gray-dark);
            color: var(--gray-dark);
            font-size: 0.85em;
            height: auto;
            border-radius: 4px;
            padding: 0.8em;
            &:hover {
              background-color: var(--gray-dark);
              color: #fff;
            }
          }
        }
      }
    }
  }

  .btn-set {
    display: flex;
    width: 100%;
    overflow: hidden;

    &.close-only {
      justify-content: center;
      position: absolute;
      right: 0;
      top: 0;
      width: var(--btn-h);
      height: var(--btn-h);
      border-radius: 50%;
      padding: 0;

      a.no.cancel {
        font-size: 1.2rem;
        margin: 0;
        background-color: transparent;
        color: var(--gray-dark);
        display: flex;
        align-items: center;
        padding: 0;
        justify-content: center;
        border: 0;
      }
    }
    a {
      height: 60px;
      line-height: 60px;
      color: #fff;
      font-weight: bold;
      text-align: center;
      background-color: var(--gray-mid);
      width: 100%;
      transition: background 0.3s;
      &:first-child:nth-last-child(3),
      &:first-child:nth-last-child(3) ~ a:first-child {
        background-color: var(--gray-light);
      }
      &.submit {
        background-color: var(--main);
      }
      img {
        vertical-align: middle;
      }
    }

    &:not(.close-only) a:hover {
      background-color: var(--gray-dark);
    }
    a.submit:hover {
      background-color: var(--main-deep);
    }
    a.disabled,
    a.submit.disabled {
      background-color: var(--gray-light);
      color: rgba(255, 255, 255, 0.8);
      pointer-events: none;
      cursor: default;
    }
    a.disabled:hover,
    a.submit.disabled:hover {
      background-color: var(--gray-light);
    }
  }

  .no {
    margin-top: 20px;
    color: var(--white);
    font-weight: bold;
    transition: color 0.3s;
    position: relative;
    z-index: 2;
    border: 2px solid var(--white);
    border-radius: 10px;
    padding: 15px;
    opacity: 0.5;
    &:hover {
      color: #fff;
    }
  }

  /* Forms & tables inside popup */
  .popup-content {
    li > dl {
      border-top: 1px solid var(--gray-border);
      padding-top: 20px;
      margin-top: 10px;
      &.form {
        border: 0;
        padding-top: 0;
      }
      dt {
        font-weight: bold;
        font-size: 0.9em;
        color: var(--gray-mid);
      }
      dd {
        border-bottom: 1px solid var(--gray-border);
        padding-bottom: 20px;
        word-break: keep-all;
      }
      &.form dt {
        margin-bottom: 10px;
      }
      &.form dd {
        margin-bottom: 0;
        padding-bottom: 0;
      }
      & dd + dt {
        margin-top: 20px;
      }
    }

    .inquiry {
      text-align: center;
      margin-top: 10px;
      cursor: pointer;
      display: block;
      &:hover {
        color: var(--main);
      }
    }

    table .inputs {
      min-height: initial;
      input,
      select {
        height: var(--input-h);
      }
    }
    .agree {
      border: 1px solid var(--gray-border);
      border-radius: 6px;
      padding: 20px;
    }
  }

  /* Filebox */
  .filebox {
    input {
      border-radius: 5px 0 0 5px;
      border-right: 0;
    }
    label {
      font-weight: bold;
      border: none;
      background-color: var(--gray-light);
      color: #fff;
      padding: 0 15px;
      flex-shrink: 0;
    }
  }
}

/* ===== Variants ===== */
.modal.login {
  .modal-popup {
    position: static;
    overflow: visible;
    h1 {
      width: fit-content;
      font-weight: 900;
    }
    .popup-content {
      max-height: 100%;
      background-color: #fff;

      &.split {
        flex-direction: row;
        flex-wrap: nowrap;
        width: initial;
        overflow: hidden;
        background-color: transparent;
        gap: 10px;
        position: static;
      }
      > li {
        background-color: var(--white);
        border-radius: 18px;
        flex-grow: 1;
        border-bottom: 0;
        width: 100%;
        padding: var(--padding);
        gap: 2px;
        overflow-y: auto;

        &.non-login {
          background-color: var(--gray-pale);
          border: 0;
        }

        .login-form {
          .tab-content > & {
            margin-top: 0;
          }
          display: flex;
          gap: 8px;
          flex-direction: column;
          margin-top: 20px;
          padding: 0;
          label {
            font-weight: bold;
            margin-top: 10px;
            &:nth-child(1) {
              margin-top: 0;
            }
          }
          .info.login-form {
            padding: 1em;
          }
          .inputs {
            display: flex;
            flex-direction: row;
            flex-wrap: wrap;
            gap: 8px;
            &.nowrap {
              flex-direction: row;
              flex-wrap: nowrap;
              input,
              select {
                width: 30%;
              }
            }
            select {
              flex-grow: 0;
              width: fit-content;
            }
            input {
              flex-grow: 1;
              &[type='tel'] {
                max-width: 120px;
                width: 30%;
              }
              &.birth {
                max-width: 100%;
              }
            }
          }
          .button {
            border: 0;
          }
        }

        .login-form + .join-find {
          margin-top: 16px;
        }

        .join-find > div {
          margin-top: 4px;

          a {
            font-weight: bold;
            text-decoration: underline;
          }
        }
      }
      .btn-set {
        right: 10px;
        top: 10px;
        box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
        a.no.cancel {
          background-color: var(--white);
          color: var(--black);
          opacity: 1;
        }
      }
    }
    a.lined {
      border: 2px solid var(--gray-dark);
      font-weight: bold;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 6px;
      font-size: 1.2em;

      height: var(--btn-h);
      &:hover {
        border-color: var(--main);
        color: var(--main);
      }
      .login-form + & {
        margin-top: 10px;
      }
    }
  }
}

.modal.ticket {
  .modal-popup {
    border-radius: 0;
    box-shadow: none;

    .popup-content {
      border-radius: 0;
      box-shadow: none;
      overflow-x: hidden;
      overflow-y: auto;
      max-height: 100%;
      position: relative;
      background-color: transparent;
      padding: 0 10px;

      .ticket-img {
        background-color: #fff;
        border-radius: 20px;
        overflow: hidden;
        flex-shrink: 0;
        position: relative;
        width: 400px;
      }

      .subscr {
        color: #fff;
        margin-top: 20px;
        display: flex;
        flex-direction: column;
        gap: 6px;
        width: 400px;

        p {
          line-height: 1.2;
          font-size: 0.8em;

          &::before {
            content: '•';
          }
        }
      }

      .ticket-printing {
        position: absolute;
        inset: 0;
        padding-top: 20%;
        line-height: 1.4;

        .qrcode {
          padding: 5% 30%;
        }

        .name {
          font-weight: bold;
          text-align: center;
          font-size: 1.7em;
          line-height: 1.3;
          color: #000;
        }

        .remain {
          text-align: center;
          font-size: 1.1em;
          display: block;
          color: var(--gray-mid);
          margin-bottom: 1%;

          span {
            color: var(--gray-dark);
          }

          .num {
            font-weight: bold;
            color: var(--main);
          }
        }

        .info {
          display: flex;
          justify-content: space-between;
          padding: 4% 7%;
          gap: 4%;
          background-color: transparent;

          dt {
            font-weight: bold;
            color: var(--gray-light);
            font-size: 0.85em;
          }

          dd {
            font-size: 1.1em;
          }
        }

        .date {
          font-weight: bold;
          text-align: center;
          font-size: 1.4em;
          color: #000;
        }
      }

      .ticket-bg {
        img {
          width: 400px;
          display: none;
        }
      }
    }
  }

  .ticket-bg {
    width: 400px;
    aspect-ratio: 8.6/15;
    background: url(../../images/img/ticket.svg) no-repeat center bottom/100% auto;
  }
}

/* Stamp */
.stamp {
  --color: var(--main);
  position: absolute;
  width: 240px;
  height: 240px;
  border: 4px solid var(--color);
  border-radius: 50%;
  opacity: 1;
  transform-origin: center;
  transform: rotate(-30deg);
  left: 20%;
  bottom: 10%;
  padding: 10px;
  box-sizing: border-box;
  color: var(--color);
  z-index: 3;
  mix-blend-mode: multiply;
  font-weight: 900;
  font-size: 2.5em;
  text-align: center;
  line-height: 212px;
  &::before {
    content: '';
    width: 212px;
    height: 212px;
    left: 10px;
    top: 10px;
    border-radius: 50%;
    border: 10px solid var(--color);
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    position: absolute;
  }
  &.used {
    --color: rgb(0, 149, 255);
  }
  &.expired {
    --color: orangered;
  }
  &.canceled,
  &.unabled {
    --color: rgb(171, 0, 0);
  }
}
.item .stamp {
  bottom: initial;
  top: var(--padding);
  mix-blend-mode: hard-light;
  z-index: 100;
}

.cal-huge-full .mask,
div.max {
  width: 100vw !important;
}

@keyframes certok {
  0% {
    background-color: var(--main);
  }
  50% {
    background-color: var(--main-light);
  }
  100% {
    background-color: var(--main);
  }
}

/* Modal open state */
.modal-on {
  overflow: hidden;
}

/* Sanctions size */
.modal.sanctions {
  .modal-popup {
    width: 340px;
  }
  .modal-popup .head strong {
    color: var(--main);
  }
}

/* System modal tweaks */
.modal.system {
  &.error {
    background-color: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
  }
  .popup-content {
    max-height: calc(100% - var(--input-h));
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  }
  .modal-popup {
    box-shadow: 60px 60px 60px rgba(0, 0, 0, 0.5);
  }
}

/* Lottery log */
.lottery-log {
  .modal-popup {
    max-width: 700px;
    width: fit-content;
  }
  .list.horizon.log {
    gap: 10px;
    margin-top: var(--padding);
    li {
      padding: 20px;
      border: 1px solid var(--gray-border);
      border-radius: 8px;
      &.canceled {
        background-color: var(--gray-pale);
        text-decoration: line-through;
        opacity: 0.5;
      }
    }
  }
}

/* Privacy / forms */
.popup-content {
  .form {
    margin-top: 30px;
  }
  .form + div {
    margin-top: 30px;
  }
  .form h4,
  .privacy h4 {
    margin-bottom: 12px;
  }
  .privacy {
    .agreement {
      padding: 20px;
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    ul.agree {
      display: flex;
      flex-direction: column;
      gap: 6px;
      li {
        display: flex;
        gap: 5px;
        color: var(--gray-mid);
        line-height: 1.2;
        &::before {
          content: '•';
          opacity: 0.5;
        }
        ul li::before {
          content: '-';
        }
        strong {
          color: var(--gray-dark);
        }
      }
    }
    .agreement .inputs {
      justify-content: center;
      font-size: 1.3em;
      font-weight: bold;
      margin-top: 10px;
    }
  }
}

.modal.program-detail {
  .popup-content {
    max-width: 800px;
    > li {
      padding: 0;
    }
  }

  .program-detail-body {
    display: flex;
    flex-direction: column;
  }

  .program-detail-thumb {
    order: 2;
    overflow: hidden;
    background: #f3f5f8;
  }

  .program-detail-copy {
    order: 1;
    padding: var(--padding);
    .program-detail-category {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      color: var(--color, var(--main));
      font-size: 0.95em;
      font-weight: 700;

      .program-detail-category-icon {
        font-size: 1.15em;
        line-height: 1;
      }
    }

    p {
      color: var(--gray-mid);
    }
  }

  .program-detail-facts {
    margin-top: 20px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0;
    border: 1px solid var(--gray-border);
    border-radius: 8px;

    dl {
      display: grid;
      grid-template-columns: 60px minmax(0, 1fr);
      gap: 8px 14px;
      margin: 0;
      padding: 15px;
      border-bottom: 1px solid var(--gray-border);
      margin-bottom: -1px;
      word-break: keep-all;
      &:nth-child(even) {
        border-left: 1px solid var(--gray-border);
      }
    }

    dt {
      font-weight: 700;
      color: var(--gray-dark);
    }

    dd {
      margin: 0;
      color: var(--gray-mid);

      .data-date {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 4px;
      }

      .period-days {
        display: inline-flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 3px;
      }

      .period-weekly {
        aspect-ratio: 1 / 1;
        height: 20px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 10em;
        font-size: 10px;
        font-weight: 700;
        line-height: 1;
        border: 1px solid var(--gray-border);
        vertical-align: text-bottom;
      }
    }
  }
}

/* Additional responsive targets placed under their classes */
.my {
}
.reserved-my-ticket {
}
.info-sub {
}

/* ==========================================================================
   반응형 스타일 (Responsive Styles)
   ========================================================================== */

@media (max-width: 812px) {
  .modal {
    max-width: 100vw;

    &.on {
      padding: 5px;

      &.system {
        padding: 20px;
      }

      &:has(.calendar) {
        padding: 0;
        backdrop-filter: initial;
        overflow: visible;

        .modal-popup {
          height: 100%;
          overflow: visible;

          .popup-content {
            flex-grow: 1;
            height: 100%;
            overflow: visible;

            .calendar {
              height: 100%;
              overflow: visible;

              .calendar-in {
                height: 100%;
                overflow-y: auto;

                .pignose-calendar {
                  border: 0;
                  overflow: visible;
                }
              }
            }
          }
        }
      }
    }

    .reserv-ui {
      a.submit,
      a.pay {
        display: none;
      }
    }

    .popup-content > li {
      padding: 30px 20px;
    }

    .modal-popup {
      max-width: 100%;
      max-height: calc(100% - 10px);
      border-radius: 20px;
      min-width: 80%;

      .modal.login & {
        overflow-y: auto;

        .popup-content {
          &.split {
            overflow-y: auto;
            flex-direction: column;
            flex-wrap: nowrap;
          }
        }
      }
    }

    .btn-set a {
      height: var(--btn-h);
      line-height: var(--btn-h);
    }

    .filebox {
      label,
      input {
        font-size: 12px;
      }
    }
  }

  .modal.login {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;

    .popup-content {
      max-height: initial;
      flex-grow: 1;

      &.split > li.non-login {
        border: 0;
      }
    }
  }

  .modal.ticket {
    .popup-content {
      .subscr {
        padding-left: 20px;
        width: 100%;
      }

      .ticket-img {
        width: 100%;
      }

      .ticket-printing {
        font-size: 1.2em;
      }
    }
  }

  .lottery-log {
    .list.horizon.log li {
      padding-right: 10px;

      .btnset .button {
        flex-direction: column;
      }

      .info-sub {
        flex-wrap: wrap;
        row-gap: 5px;
        font-size: 1em;

        .status {
          width: 100%;
          font-size: 1em;
        }
      }
    }
  }

  .my {
    .list.horizon.log li .info {
      gap: 4px;
    }
  }

  .reserved-my-ticket > li {
    font-size: 1em;
  }

  .info-sub {
    font-size: 1em;
  }

  .modal.program-detail {
    .program-detail-body {
      grid-template-columns: 1fr;
    }

    .program-detail-facts {
      grid-template-columns: 1fr;

      dl {
        grid-template-columns: 60px minmax(0, 1fr);
        gap: 4px;

        &:nth-child(even) {
          border-left: 0;
        }
      }
    }
  }
}
