* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #11131f; }
body { font-family: Arial, Helvetica, sans-serif; color: #f6f6fb; }
button { font-family: inherit; }
.game { position: relative; width: 100%; height: 100%; overflow: hidden; background: #11131f; isolation: isolate; }
#game { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
[hidden] { display: none !important; }
.screen { position: absolute; z-index: 4; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; padding: 30px 22px; background: rgba(13, 15, 27, .9); }
.menu h1 { margin: 0 0 28px; color: #fff; font-size: clamp(34px, 7vw, 64px); line-height: 1; letter-spacing: .12em; text-shadow: 4px 4px 0 #7651d8; }
.level-list { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; width: min(820px, 100%); max-height: min(68vh, 620px); overflow: auto; overscroll-behavior: contain; padding: 5px 8px 12px; }
.level-card { position: relative; min-width: 0; min-height: 88px; border: 2px solid #30364f; border-radius: 7px; background: linear-gradient(145deg, #252b43, #171b2d); color: #fff; font: 800 14px Arial, sans-serif; cursor: pointer; transition: transform .12s, border-color .12s, background .12s; }
.level-card:hover, .level-card:focus-visible { transform: translateY(-3px); border-color: #61e8f0; background: linear-gradient(145deg, #38436a, #20263d); outline: none; }
.level-card .number { display: block; margin-bottom: 7px; color: #62e7ee; font-size: 11px; letter-spacing: .14em; }
.level-card.creator { border-color: #775ce0; color: #d6cbff; }
.editor-tools { position: absolute; z-index: 3; top: 22px; left: 50%; display: none; gap: 8px; transform: translateX(-50%); }
.editor-tools.visible { display: flex; }
.tool { width: 45px; height: 43px; border: 2px solid #465070; border-radius: 6px; background: #20263a; color: #fff; font-size: 20px; font-weight: 800; cursor: pointer; }
.tool.selected { border-color: #59e4ed; color: #59e4ed; }
.tool.action { border-color: #7b66db; }
.hud { position: absolute; z-index: 2; top: 22px; left: 50%; display: none; align-items: center; gap: 10px; width: min(420px, 68vw); transform: translateX(-50%); pointer-events: none; }
.hud.visible { display: flex; }
.progress-track { flex: 1; height: 9px; overflow: hidden; border: 2px solid #f3f3f7; border-radius: 8px; background: #25283a; }
.progress-fill { width: 0; height: 100%; background: #53e7ee; transition: width .08s linear; }
.progress-percent { min-width: 38px; color: white; font-size: 13px; font-weight: 800; text-shadow: 1px 2px #11131f; }
.modal-screen { position: absolute; z-index: 5; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(7, 9, 18, .48); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.modal-card { width: min(360px, 100%); padding: 26px; border: 2px solid #424a68; border-radius: 10px; background: #191d2d; box-shadow: 0 12px 45px rgba(0, 0, 0, .45); text-align: center; }
.modal-card h2 { margin: 0 0 20px; color: #fff; font-size: 25px; letter-spacing: .1em; }
.modal-button { min-height: 44px; border: 2px solid #434c6b; border-radius: 6px; background: #252b40; color: #fff; font-size: 13px; font-weight: 800; letter-spacing: .08em; cursor: pointer; }
.modal-button:hover, .modal-button:focus-visible { border-color: #62e7ee; outline: none; }
.modal-button.primary { width: 100%; border-color: #5a9fa9; background: #24444c; }
.modal-button.secondary { width: 100%; margin-top: 10px; }
.mode-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.mode-options .modal-button { width: 100%; }
.result-stats { display: grid; grid-template-columns: 1fr auto; gap: 12px; margin: 0 0 22px; text-align: left; }
.result-stats span { color: #abb3ca; font-size: 12px; letter-spacing: .08em; }
.result-stats strong { color: #62e7ee; font-size: 13px; text-align: right; }
.frame { position: absolute; z-index: 1; inset: 12px; border: 2px solid rgba(221, 226, 255, .2); pointer-events: none; }
.corner { position: absolute; width: 22px; height: 22px; border: solid #62e7ee; }
.corner-tl { top: -2px; left: -2px; border-width: 4px 0 0 4px; }
.corner-tr { top: -2px; right: -2px; border-width: 4px 4px 0 0; }
.corner-bl { bottom: -2px; left: -2px; border-width: 0 0 4px 4px; }
.corner-br { right: -2px; bottom: -2px; border-width: 0 4px 4px 0; }
@media (max-width: 650px) {
  .level-list { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; max-height: 68vh; }
  .level-card { min-height: 72px; padding: 7px 4px; font-size: 12px; }
  .editor-tools { top: 16px; gap: 5px; }
  .tool { width: 40px; height: 39px; }
  .modal-card { padding: 22px; }
}
