@import url("https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css");

:root {
  --bg-0: #071127;
  --bg-1: #0d1a3a;
  --bg-2: #182457;
  --surface: rgba(12, 23, 52, 0.68);
  --surface-strong: rgba(17, 30, 68, 0.9);
  --line: rgba(176, 193, 255, 0.3);
  --line-strong: rgba(83, 223, 255, 0.62);
  --text: #f5f7ff;
  --muted: #aab3d6;
  --accent: #7c5cff;
  --accent-blue: #4a90e2;
  --cyan: #00d4ff;
  --gold: #ffcc70;
  --danger: #ff5c7a;
  --ok: #7dffbf;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.38);
  --radius: 8px;
  font-family: Pretendard, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 22% 16%, rgba(0, 212, 255, 0.18), transparent 34%),
    radial-gradient(circle at 80% 22%, rgba(255, 204, 112, 0.12), transparent 28%),
    linear-gradient(145deg, rgba(124, 92, 255, 0.18), transparent 42%),
    linear-gradient(20deg, rgba(0, 212, 255, 0.12), transparent 50%),
    var(--bg-0);
  color: var(--text);
}

body {
  min-width: 320px;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  color: var(--text);
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

#worldCanvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  background: var(--bg-0);
}

.hidden {
  display: none !important;
}

.fatal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  background: var(--bg-0);
}

.loading-screen,
.start-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(7, 17, 39, 0.5), rgba(7, 17, 39, 0.2)),
    radial-gradient(circle at 50% 15%, rgba(0, 212, 255, 0.24), transparent 42%),
    radial-gradient(circle at 22% 74%, rgba(255, 204, 112, 0.12), transparent 34%);
  text-align: center;
}

.loading-screen {
  z-index: 60;
  gap: 12px;
  background: var(--bg-0);
}

.loading-screen strong {
  font-size: 24px;
  line-height: 1;
}

.loading-screen span {
  color: var(--muted);
  font-size: 14px;
}

.loader-orbit {
  width: 52px;
  height: 52px;
  border: 1px solid rgba(0, 212, 255, 0.32);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 1.1s linear infinite;
}

.start-overlay {
  z-index: 40;
}

.start-glow {
  position: absolute;
  inset: 12%;
  background:
    linear-gradient(110deg, transparent, rgba(124, 92, 255, 0.18), transparent),
    linear-gradient(70deg, transparent, rgba(0, 212, 255, 0.12), transparent);
  filter: blur(24px);
  opacity: 0.82;
  pointer-events: none;
}

.start-content {
  position: relative;
  width: min(560px, 92vw);
  padding: 34px 28px 28px;
  border: 1px solid rgba(159, 183, 255, 0.28);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(16, 29, 68, 0.7), rgba(9, 15, 35, 0.58));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.start-content h1 {
  margin: 0;
  color: var(--text);
  font-size: clamp(44px, 8vw, 82px);
  line-height: 0.9;
  font-weight: 800;
}

.subtitle {
  margin: 10px 0 22px;
  color: var(--cyan);
  font-size: 18px;
  font-weight: 700;
}

#startExploreButton,
.primary-button,
.ad-popup button#adPopupLink {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  box-shadow: 0 10px 28px rgba(0, 212, 255, 0.24);
  color: white;
  font-size: 14px;
  font-weight: 800;
}

#startExploreButton:hover,
.primary-button:hover,
.ad-popup button#adPopupLink:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.start-help {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 22px auto 12px;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 14px;
}

.start-help li {
  min-height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
}

.start-note {
  margin: 12px 0 0;
  color: var(--text);
  font-size: 14px;
}

.control-hint {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 15;
  min-width: 124px;
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}

.control-hint strong {
  color: var(--text);
  font-size: 13px;
}

.top-bar {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 18;
  width: min(290px, calc(100vw - 28px));
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  justify-items: end;
  gap: 10px;
  pointer-events: none;
}

.login-button,
.mode-button {
  min-width: 58px;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.17);
  border-radius: var(--radius);
  background: rgba(13, 28, 65, 0.68);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  backdrop-filter: blur(12px);
  pointer-events: auto;
}

.mode-button {
  min-width: 86px;
  border-color: rgba(0, 212, 255, 0.28);
  color: var(--cyan);
}

.mode-button.locked {
  border-color: rgba(255, 204, 112, 0.46);
  color: var(--gold);
}

.login-button:hover,
.mode-button:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}

.chat-widget {
  width: 260px;
  min-width: 220px;
  max-width: calc(100vw - 28px);
  min-height: 208px;
  max-height: 48vh;
  resize: both;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(8, 13, 31, 0.58);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  pointer-events: auto;
}

.chat-widget header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.chat-widget small {
  color: var(--muted);
  font-weight: 700;
}

.chat-messages {
  min-height: 92px;
  overflow-y: auto;
  display: grid;
  align-content: end;
  gap: 6px;
  padding: 10px;
  color: var(--text);
  font-size: 12px;
}

.chat-message {
  display: grid;
  gap: 2px;
  padding: 7px 8px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.06);
  overflow-wrap: anywhere;
}

.chat-message.system {
  color: var(--gold);
  background: rgba(255, 204, 112, 0.08);
}

.chat-message .meta {
  color: var(--muted);
  font-size: 11px;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr 54px;
  gap: 6px;
  padding: 8px 10px 6px;
}

.chat-form input,
.admin-panel input,
.admin-panel textarea,
.admin-panel select,
.login-modal input {
  width: 100%;
  min-height: 34px;
  border: 1px solid rgba(169, 185, 255, 0.22);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  outline: none;
}

.chat-form input,
.login-modal input {
  padding: 0 10px;
}

.chat-form input:focus,
.admin-panel input:focus,
.admin-panel textarea:focus,
.admin-panel select:focus,
.login-modal input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.13);
}

.chat-form button {
  min-height: 34px;
  border-radius: var(--radius);
  background: rgba(0, 212, 255, 0.16);
  color: var(--cyan);
  font-size: 12px;
  font-weight: 800;
}

.chat-status {
  min-height: 20px;
  margin: 0;
  padding: 0 10px 8px;
  color: var(--muted);
  font-size: 11px;
}

.ad-popup {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  width: min(520px, calc(100vw - 28px));
  min-height: 128px;
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 14px;
  padding: 12px 42px 12px 12px;
  border: 1px solid rgba(0, 212, 255, 0.34);
  border-radius: var(--radius);
  background: rgba(8, 13, 31, 0.76);
  box-shadow: 0 18px 58px rgba(0, 0, 0, 0.46), 0 0 32px rgba(0, 212, 255, 0.14);
  backdrop-filter: blur(18px);
  transform: translateX(-50%);
}

.popup-close,
.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.popup-close:hover,
.modal-close:hover {
  color: var(--text);
  border-color: var(--danger);
}

.ad-popup-thumb {
  min-height: 96px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  background-size: cover;
  background-position: center;
}

.ad-popup-copy {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 8px;
}

.ad-popup-copy strong {
  font-size: 18px;
  line-height: 1.2;
}

.ad-popup-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.ad-popup-copy small {
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.35;
}

.ad-popup button#adPopupLink {
  width: max-content;
  max-width: 100%;
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 4, 12, 0.58);
  backdrop-filter: blur(8px);
}

.login-modal {
  position: relative;
  width: min(360px, 94vw);
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.login-modal h2 {
  margin: 0 0 4px;
  font-size: 22px;
}

.login-modal label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.form-error,
.admin-message {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
  font-size: 12px;
}

.admin-message.ok {
  color: var(--ok);
}

.admin-panel {
  position: fixed;
  top: 14px;
  left: 14px;
  bottom: 14px;
  z-index: 22;
  width: min(390px, calc(100vw - 28px));
  display: grid;
  grid-template-rows: auto auto 1fr;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(14, 30, 70, 0.82), rgba(7, 12, 31, 0.72));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  overflow: hidden;
}

.admin-panel.collapsed {
  bottom: auto;
  width: 250px;
}

.admin-panel.collapsed .admin-tabs,
.admin-panel.collapsed .admin-content {
  display: none;
}

.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}

.admin-title {
  display: grid;
  gap: 2px;
}

.admin-title strong {
  font-size: 14px;
}

.admin-title small {
  color: var(--muted);
  font-size: 11px;
}

.admin-actions {
  display: flex;
  gap: 6px;
}

.icon-button,
.small-button,
.danger-button,
.ghost-button {
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.icon-button {
  width: 32px;
  padding: 0;
}

.danger-button {
  color: var(--danger);
}

.ghost-button {
  color: var(--muted);
}

.small-button:hover,
.icon-button:hover,
.ghost-button:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}

.danger-button:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.admin-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  padding: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.admin-tabs button {
  min-height: 30px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.admin-tabs button.active {
  background: rgba(0, 212, 255, 0.16);
  color: var(--cyan);
}

.admin-content {
  overflow-y: auto;
  padding: 12px;
}

.ad-list {
  display: grid;
  gap: 10px;
}

.ad-card {
  display: grid;
  gap: 9px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.055);
}

.ad-card-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.ad-card strong {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.badge {
  width: max-content;
  padding: 3px 7px;
  border-radius: var(--radius);
  background: rgba(124, 92, 255, 0.18);
  color: #d7d0ff;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.badge.off {
  background: rgba(255, 92, 122, 0.14);
  color: #ff9caf;
}

.ad-card p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.ad-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.admin-form {
  display: grid;
  gap: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.form-grid.single {
  grid-template-columns: 1fr;
}

.admin-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.form-help {
  color: rgba(170, 179, 214, 0.82);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
}

.admin-panel input,
.admin-panel select {
  padding: 0 9px;
}

.admin-panel textarea {
  min-height: 84px;
  padding: 9px;
  resize: vertical;
}

.check-row {
  display: flex !important;
  align-items: center;
  gap: 8px !important;
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

.form-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.json-area {
  min-height: 180px !important;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 12px;
}

.placement-hud {
  position: fixed;
  left: 50%;
  top: 72px;
  z-index: 24;
  width: min(430px, calc(100vw - 28px));
  display: grid;
  gap: 5px;
  padding: 12px 14px;
  border: 1px solid rgba(0, 212, 255, 0.4);
  border-radius: var(--radius);
  background: rgba(10, 24, 58, 0.8);
  box-shadow: 0 14px 42px rgba(0, 0, 0, 0.34), 0 0 34px rgba(0, 212, 255, 0.16);
  color: var(--text);
  font-size: 12px;
  text-align: center;
  transform: translateX(-50%);
  backdrop-filter: blur(16px);
  pointer-events: none;
}

.placement-hud strong {
  color: var(--cyan);
  font-size: 14px;
}

.placement-hud span {
  color: var(--muted);
}

.mobile-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 17;
  display: none;
  pointer-events: none;
}

.mobile-controls p {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 122px;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  background: rgba(8, 13, 31, 0.62);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  backdrop-filter: blur(12px);
}

.mobile-pad {
  position: fixed;
  left: 16px;
  bottom: 16px;
  width: 118px;
  height: 98px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 6px;
  pointer-events: auto;
}

.mobile-pad button {
  min-width: 34px;
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  background: rgba(8, 13, 31, 0.76);
  color: var(--cyan);
  font-weight: 900;
}

.mobile-pad button:nth-child(1) {
  grid-column: 2;
}

.mobile-pad button:nth-child(2) {
  grid-column: 1;
  grid-row: 2;
}

.mobile-pad button:nth-child(3) {
  grid-column: 2;
  grid-row: 2;
}

.mobile-pad button:nth-child(4) {
  grid-column: 3;
  grid-row: 2;
}

.mobile-look-area {
  position: fixed;
  right: 16px;
  bottom: 18px;
  width: min(38vw, 180px);
  height: 92px;
  display: grid;
  place-items: center;
  border: 1px dashed rgba(0, 212, 255, 0.38);
  border-radius: var(--radius);
  background: rgba(8, 13, 31, 0.48);
  color: rgba(245, 247, 255, 0.6);
  font-size: 12px;
  font-weight: 800;
  pointer-events: auto;
  touch-action: none;
}

.toast {
  position: fixed;
  left: 50%;
  top: 16px;
  z-index: 70;
  max-width: min(480px, calc(100vw - 28px));
  padding: 10px 12px;
  border: 1px solid rgba(0, 212, 255, 0.28);
  border-radius: var(--radius);
  background: rgba(8, 13, 31, 0.84);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 13px;
  transform: translateX(-50%);
  backdrop-filter: blur(14px);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 860px) {
  .control-hint {
    top: 12px;
    left: 12px;
  }

  .top-bar {
    top: 12px;
    right: 12px;
    width: min(250px, calc(100vw - 24px));
  }

  .chat-widget {
    width: 238px;
    min-height: 176px;
    max-height: 38vh;
  }

  .admin-panel {
    left: 10px;
    right: 10px;
    top: 56px;
    bottom: 146px;
    width: auto;
  }

  .admin-tabs {
    grid-template-columns: repeat(2, 1fr);
  }

  .mobile-controls {
    display: block;
  }

  .ad-popup {
    bottom: 148px;
    grid-template-columns: 92px 1fr;
    min-height: 110px;
  }

  .ad-popup-thumb {
    min-height: 84px;
  }
}

@media (max-width: 560px) {
  .start-content {
    padding: 26px 16px 18px;
  }

  .start-help,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .control-hint {
    display: none;
  }

  .chat-widget {
    width: 218px;
  }

  .ad-popup {
    width: calc(100vw - 20px);
    grid-template-columns: 1fr;
    padding: 12px 42px 12px 12px;
  }

  .ad-popup-thumb {
    min-height: 84px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
