:root {
  color-scheme: dark;
  --bg: #050b0f;
  --panel: #0b151b;
  --panel-strong: #101e26;
  --line: #27404c;
  --line-bright: #466c7d;
  --text: #eef7fa;
  --muted: #86a1ad;
  --green: #4ee0a0;
  --green-soft: rgb(78 224 160 / 11%);
  --blue: #3a8dff;
  --red: #ff3038;
  font-family: "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html,
body {
  width: 100%;
  min-width: 768px;
  height: 100%;
  min-height: 560px;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
}

button {
  color: inherit;
  font: inherit;
  touch-action: manipulation;
}

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

[hidden] {
  display: none !important;
}

.app-frame {
  position: relative;
  width: 100%;
  height: 100%;
  color: var(--text);
  background:
    linear-gradient(rgb(39 64 76 / 6%) 1px, transparent 1px),
    linear-gradient(90deg, rgb(39 64 76 / 6%) 1px, transparent 1px),
    linear-gradient(180deg, #071117 0%, var(--bg) 100%);
  background-size: 32px 32px, 32px 32px, auto;
}

.app-frame::after {
  display: none;
}

.system-bar {
  display: flex;
  height: 64px;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(22px, 3vw, 42px);
  background: rgb(7 16 22 / 96%);
  border-bottom: 0;
}

.system-identity,
.system-state {
  display: flex;
  align-items: center;
  gap: 12px;
  letter-spacing: 0.08em;
}

.system-identity {
  cursor: default;
}

.system-identity > span:not(.status-light),
.system-state span {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 700;
}

.system-identity strong {
  padding-left: 12px;
  border-left: 1px solid var(--line);
  font-size: 16px;
}

.system-state {
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.system-state strong {
  color: var(--green);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.status-light {
  width: 8px;
  height: 8px;
  background: var(--green);
  border-radius: 50%;
  box-shadow: 0 0 12px rgb(78 224 160 / 72%);
}

.system-main {
  height: calc(100% - 64px);
}

.screen {
  height: 100%;
  padding: clamp(18px, 2.6vw, 40px);
}

.access-screen {
  display: grid;
  max-width: 1320px;
  overflow: hidden;
  grid-template-columns: minmax(0, 1.45fr) minmax(350px, 0.72fr);
  align-items: stretch;
  justify-content: center;
  gap: clamp(18px, 2.2vw, 30px);
  margin: 0 auto;
  padding: clamp(20px, 2.6vw, 34px);
}

.diagram-panel,
.access-panel,
.question-card,
.answer-area {
  background:
    radial-gradient(circle at 50% 45%, rgb(28 61 64 / 12%), transparent 58%),
    rgb(8 20 27 / 91%);
  border: 1px solid #2b4a56;
}

.diagram-panel {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 0;
  place-items: center;
}

.diagram-panel::before,
.access-panel::before {
  position: absolute;
  top: -1px;
  left: 50%;
  width: 84px;
  height: 2px;
  content: "";
  background: var(--green);
  box-shadow: 0 0 12px rgb(78 224 160 / 48%);
  transform: translateX(-50%);
}

.diagram-wrap {
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: clamp(45px, 7vh, 58px) clamp(14px, 1.5vw, 22px) clamp(16px, 2vw, 28px);
  place-items: start center;
  background: transparent;
}

.security-puzzle {
  --puzzle-grid-size: clamp(82px, 9.6vw, 112px);
  display: grid;
  width: max-content;
  min-height: 500px;
  max-width: 100%;
  align-content: start;
  justify-self: center;
  gap: clamp(16px, 2.2vh, 23px);
  color: #eef3f5;
}

.security-puzzle h2,
.security-puzzle h3 {
  margin: 0;
}

.security-puzzle h2 {
  margin-bottom: clamp(18px, 2.6vh, 22px);
  font-size: clamp(25px, 2.65vw, 34px);
  line-height: 1.28;
  text-align: left;
  letter-spacing: -0.025em;
}

.puzzle-section h3 {
  margin-bottom: clamp(10px, 1.25vh, 14px);
  font-size: clamp(15px, 1.6vw, 21px);
  letter-spacing: -0.015em;
}

.puzzle-section h3 span {
  margin-right: 7px;
  color: var(--green);
  font-size: 0.78em;
}

.puzzle-line {
  display: grid;
  grid-template-columns: repeat(4, var(--puzzle-grid-size)) minmax(48px, auto);
  align-items: center;
  justify-content: start;
  gap: clamp(8px, 1.1vw, 14px);
}

.mini-grid {
  display: grid;
  width: var(--puzzle-grid-size);
  aspect-ratio: 1;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 1px;
  padding: 1px;
  background: #0b1115;
}

.puzzle-cell-yellow { background: #ffed16; }
.puzzle-cell-red { background: #f51d28; }
.puzzle-cell-blue { background: #1828ed; }

.puzzle-result {
  display: flex;
  min-width: 70px;
  align-items: center;
  gap: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(17px, 1.7vw, 24px);
}

.puzzle-result > span {
  color: var(--green);
}

.puzzle-result strong {
  font-weight: 800;
}

.puzzle-result-empty {
  min-width: 48px;
}

.access-panel {
  position: relative;
  display: flex;
  width: 100%;
  height: 100%;
  min-height: 0;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: clamp(45px, 7vh, 58px) clamp(18px, 2vw, 26px) clamp(18px, 2.4vw, 30px);
}

.access-content {
  display: flex;
  width: 100%;
  min-height: 500px;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.13em;
}

.access-panel h1,
.quiz-topline h1,
.result-screen h1 {
  margin: 0;
  letter-spacing: -0.04em;
}

.access-panel h1 {
  width: 100%;
  max-width: 250px;
  margin-bottom: 0;
  font-size: clamp(25px, 2.65vw, 34px);
  line-height: 1.28;
  text-align: center;
  text-wrap: balance;
  word-break: keep-all;
}

.access-description {
  min-height: 34px;
  margin: 14px 0 45px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
  word-break: keep-all;
}

.code-display {
  display: grid;
  width: min(100%, 330px);
  grid-template-columns: repeat(4, 1fr);
  align-self: center;
  gap: 14px;
}

.code-display span {
  display: grid;
  height: 72px;
  place-items: center;
  color: #f5f7ff;
  background: #061016;
  border: 1px solid var(--line-bright);
  border-radius: 2px;
  box-shadow: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 28px;
  font-weight: 800;
}

.code-display span.filled {
  color: #fff;
  background: #0c1b23;
  border-color: var(--green);
  box-shadow: inset 0 0 18px var(--green-soft);
}

.code-display span.active {
  border-color: var(--green);
  box-shadow: 0 0 10px rgb(78 224 160 / 22%);
}

.feedback {
  min-height: 20px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.access-panel .feedback {
  height: 18px;
  min-height: 18px;
  margin: 10px 0 18px;
  text-align: center;
}

.feedback.valid {
  color: var(--green);
}

.feedback.invalid {
  color: #ff747a;
}

.code-pad {
  display: flex;
  width: 100%;
  flex-direction: column;
  max-width: 390px;
  gap: 9px;
}

.access-panel .code-pad {
  margin-top: 40px;
}

.code-pad button,
.hangul-keyboard button {
  min-width: 0;
  background: rgb(255 255 255 / 4%);
  border: 1px solid rgb(195 213 221 / 22%);
  border-radius: 5px;
  box-shadow: none;
  font-weight: 800;
}

.code-pad button {
  min-width: 0;
  min-height: 46px;
  flex: 1;
  background: #10212a;
  border-color: #365361;
  border-radius: 6px;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 4%);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(14px, 1.5vw, 19px);
}

.code-pad button:active {
  color: #041b12;
  background: var(--green);
  border-color: var(--green);
}

.code-key-row,
.code-action-row {
  display: flex;
  justify-content: center;
  gap: 4px;
}

.code-key-row-middle {
  padding-inline: 4%;
}

.code-key-row-bottom {
  padding-inline: 6%;
}

.code-action-row {
  margin-top: 7px;
}

.code-pad .utility {
  font-family: inherit;
  font-size: 14px;
}

.code-pad .delete-key {
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

.code-pad .confirm {
  width: 100%;
  min-height: 50px;
  flex: 0 0 100%;
  color: #042016;
  background: var(--green);
  border-color: var(--green);
  box-shadow: 0 0 18px rgb(78 224 160 / 16%);
  font-family: inherit;
  font-size: 14px;
}

.shake {
  animation: shake 180ms linear 2;
}

.quiz-screen {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: clamp(10px, 1.5vh, 16px);
  padding-block: clamp(14px, 2vh, 26px);
}

.quiz-topline {
  display: block;
}

.quiz-topline h1 {
  font-size: clamp(24px, 2.5vw, 36px);
}

.question-card {
  display: grid;
  min-height: 104px;
  grid-template-columns: clamp(104px, 11vw, 132px) 1fr;
  align-items: center;
  padding: clamp(14px, 2vw, 24px);
}

.question-index {
  color: var(--green);
  font-family: "Avenir Next", "Helvetica Neue", "Apple SD Gothic Neo", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  font-size: clamp(30px, 3.7vw, 46px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.05em;
}

.question-card h2 {
  margin: 0;
  font-size: clamp(19px, 1.9vw, 26px);
  line-height: 1.48;
  white-space: pre-line;
  word-break: keep-all;
}

.answer-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
}

.answer-display {
  min-height: 50px;
  padding: 10px 14px;
  color: var(--green);
  background: #050c10;
  border: 1px solid var(--line-bright);
  font-size: clamp(20px, 2vw, 28px);
  font-weight: 800;
  letter-spacing: 0.03em;
}

.answer-display::after {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 4px;
  vertical-align: -0.1em;
  content: "";
  background: var(--green);
  animation: cursor 800ms steps(1) infinite;
}

.answer-display .placeholder {
  color: #607581;
  font-size: 15px;
  font-weight: 600;
}

.answer-area .feedback {
  margin: 0;
  text-align: right;
}

.answer-area .retry-message {
  position: fixed;
  z-index: 80;
  top: 50%;
  left: 50%;
  display: grid;
  width: min(540px, calc(100% - 80px));
  min-height: 130px;
  margin: 0;
  padding: 22px 28px;
  place-items: center;
  color: #fff;
  background: #dc0010;
  border: 2px solid #ff6670;
  border-radius: 10px;
  box-shadow: 0 0 0 100vmax rgb(65 0 5 / 62%), 0 24px 70px rgb(0 0 0 / 55%);
  font-size: clamp(18px, 2.2vw, 26px);
  font-weight: 800;
  line-height: 1.45;
  text-align: center;
  transform: translate(-50%, -50%);
  animation: error-pop 180ms ease-out;
  pointer-events: none;
}

.hangul-keyboard {
  display: flex;
  min-height: 0;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  background: rgb(9 19 25 / 94%);
  border: 1px solid var(--line);
}

.key-row {
  display: flex;
  flex: 1;
  justify-content: center;
  gap: 6px;
}

.key-row button {
  width: clamp(48px, 7vw, 86px);
  min-height: 38px;
  font-size: clamp(15px, 1.7vw, 22px);
}

.number-row button {
  font-family: "Avenir Next", "Helvetica Neue", "Apple SD Gothic Neo", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.key-row button:active {
  color: #041b12;
  background: var(--green);
  border-color: var(--green);
}

.middle-row {
  padding-inline: 3vw;
}

.bottom-row .wide {
  width: clamp(84px, 10vw, 126px);
  color: #bad0da;
  font-size: 13px;
}

.bottom-row .submit-key {
  width: clamp(108px, 12vw, 150px);
  color: #042016;
  background: var(--green);
  border-color: var(--green);
  font-size: 15px;
}

.result-screen {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: flex;
  width: 100vw;
  height: 100%;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  overflow: hidden;
  text-align: center;
}

.result-mark {
  display: grid;
  width: clamp(96px, 12vw, 150px);
  aspect-ratio: 1;
  margin-bottom: 28px;
  place-items: center;
  border: 4px solid currentColor;
  border-radius: 50%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(58px, 8vw, 102px);
  font-weight: 300;
  line-height: 1;
}

.result-screen p {
  margin: 0 0 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.2em;
}

.result-screen h1 {
  font-size: clamp(58px, 8vw, 106px);
}

.result-screen > span {
  margin-top: 16px;
  font-size: clamp(15px, 2vw, 22px);
  font-weight: 700;
}

.success-screen {
  color: #fff;
  background:
    radial-gradient(circle at center, rgb(90 175 255 / 30%), transparent 34%),
    linear-gradient(135deg, #043b85, #006bd4 48%, #034690);
}

.failure-screen {
  color: #fff;
  background: #d5000c;
}

.failure-screen .result-mark {
  width: clamp(130px, 16vw, 200px);
  margin: 0 0 20px;
  border-width: 6px;
  transform: translateY(60px);
}

.failure-screen h1 {
  position: absolute;
  top: clamp(142px, 25vh, 190px);
  left: 0;
  width: 100%;
  font-size: clamp(48px, 7vw, 84px);
  line-height: 1;
}

.failure-screen > span {
  transform: translateY(60px);
}

.denied-marquee {
  position: absolute;
  left: 0;
  display: flex;
  width: 100%;
  height: 32px;
  align-items: center;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent);
}

.denied-marquee-top {
  top: 24px;
}

.denied-marquee-bottom {
  bottom: 24px;
}

.denied-track,
.denied-sequence {
  display: flex;
  width: max-content;
  flex: none;
  align-items: center;
}

.denied-track {
  animation: denied-left 18s linear infinite;
  will-change: transform;
}

.denied-marquee-bottom .denied-track {
  animation-name: denied-right;
}

.denied-sequence span {
  display: flex;
  align-items: center;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  padding-inline: 8px;
}

.failure-active .failure-screen {
  animation: alarm-flash 620ms steps(1) infinite;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

@keyframes cursor {
  50% { opacity: 0; }
}

@keyframes error-pop {
  from {
    opacity: 0;
    transform: translate(-50%, -46%) scale(0.94);
  }
}

@keyframes alarm-flash {
  0%, 58% { filter: brightness(1); }
  59%, 100% { filter: brightness(0.48); }
}

@keyframes denied-left {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

@keyframes denied-right {
  from { transform: translateX(-50%); }
  to { transform: translateX(0); }
}

@media (max-height: 680px) {
  .system-bar { height: 54px; }
  .system-main { height: calc(100% - 54px); }
  .screen { padding-block: 12px; }
  .access-screen { gap: 24px; padding-block: 12px; }
  .access-panel { padding: 45px 18px 12px; }
  .access-panel h1 { margin-bottom: 0; font-size: 25px; }
  .access-description { margin: 8px 0 48px; font-size: 10px; }
  .code-display { width: min(100%, 300px); gap: 10px; }
  .code-display span { height: 56px; font-size: 24px; }
  .access-panel .feedback { margin-block: 5px 8px; }
  .access-panel .code-pad { margin-top: 22px; }
  .code-pad { gap: 4px; }
  .code-key-row, .code-action-row { gap: 4px; }
  .code-pad button { min-height: 34px; }
  .code-pad .confirm { min-height: 40px; }
  .question-card { min-height: 84px; }
  .answer-display { min-height: 42px; padding-block: 6px; }
  .key-row button { min-height: 31px; }
  .hangul-keyboard { padding: 7px; gap: 4px; }
  .key-row { gap: 4px; }
}
