* {
  box-sizing: border-box;
}

:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1f2937;
  background: #f3f4f6;
  font-synthesis: none;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at top, #ffffff 0, #f3f4f6 48%, #e5e7eb 100%);
}

button,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 1100px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    max(20px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.screen {
  display: none;
  min-height: calc(100vh - 40px);
  min-height: calc(100dvh - 40px);
}

.screen.active {
  display: flex;
  flex-direction: column;
}

#screen-menu,
#screen-pause,
#screen-result {
  justify-content: center;
  align-items: center;
}

.panel {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid #e5e7eb;
  border-radius: 24px;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

.menu-panel {
  width: min(100%, 520px);
  padding: 32px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 8px;
  color: #6366f1;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: clamp(2.4rem, 9vw, 4.5rem);
  line-height: 0.95;
}

h2 {
  margin-bottom: 0;
}

h3 {
  margin-bottom: 12px;
}

.lead {
  margin-bottom: 28px;
  color: #4b5563;
  font-size: 1.05rem;
  line-height: 1.55;
}

.btn,
.icon-btn {
  border: 0;
  border-radius: 16px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 120ms ease, opacity 120ms ease;
}

.btn:active,
.icon-btn:active {
  transform: scale(0.98);
}

.btn {
  min-height: 52px;
  padding: 12px 18px;
}

.btn-large {
  width: 100%;
  min-height: 60px;
  margin-top: 12px;
}

.btn-primary {
  color: #ffffff;
  background: #4f46e5;
}

.btn-secondary {
  color: #1f2937;
  background: #eef2ff;
}

.icon-btn {
  width: 52px;
  height: 52px;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  font-size: 1.2rem;
}

.progress-card {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 24px;
  padding: 16px;
  border-radius: 16px;
  background: #f9fafb;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.game-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  flex: 1;
}

.task-panel,
.preview-panel,
.code-panel {
  padding: 22px;
}

.task-panel p {
  color: #374151;
  font-size: 1.06rem;
  line-height: 1.55;
}

.preview-stage {
  display: grid;
  place-items: center;
  min-height: 220px;
  border: 2px dashed #d1d5db;
  border-radius: 20px;
  background:
    linear-gradient(45deg, #f9fafb 25%, transparent 25%),
    linear-gradient(-45deg, #f9fafb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f9fafb 75%),
    linear-gradient(-45deg, transparent 75%, #f9fafb 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}

.preview-object {
  width: 90px;
  height: 90px;
  border-radius: 18px;
  background: #3b82f6;
  box-shadow: 0 16px 35px rgba(15, 23, 42, 0.18);
  transition:
    background-color 260ms ease,
    transform 260ms ease,
    width 260ms ease,
    height 260ms ease,
    border-radius 260ms ease;
}

.feedback {
  min-height: 24px;
  margin: 14px 0 0;
  color: #4b5563;
  font-weight: 700;
}

.feedback.success {
  color: #047857;
}

.feedback.error {
  color: #b91c1c;
}

.code-panel label {
  display: block;
  margin-bottom: 10px;
  font-weight: 900;
}

#code-input {
  width: 100%;
  min-height: 130px;
  resize: vertical;
  padding: 16px;
  border: 2px solid #d1d5db;
  border-radius: 16px;
  outline: none;
  background: #111827;
  color: #f9fafb;
  font-family: "Courier New", Courier, monospace;
  font-size: 1rem;
  line-height: 1.6;
}

#code-input:focus {
  border-color: #6366f1;
}

.code-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 12px;
}

.hint {
  margin-top: 14px;
  padding: 14px;
  border-radius: 14px;
  background: #fffbeb;
  color: #92400e !important;
  font-weight: 700;
}

.hidden {
  display: none;
}

.result-panel {
  max-width: 520px;
}

.result-icon {
  margin-bottom: 8px;
  font-size: 4rem;
}

.stars {
  margin: 18px 0;
  font-size: 2.3rem;
  letter-spacing: 0.1em;
}

.result-details {
  color: #4b5563;
  line-height: 1.7;
}

@media (min-width: 700px) {
  .game-grid {
    grid-template-columns: 0.85fr 1.15fr;
    align-items: stretch;
  }

  .code-panel {
    grid-column: 1 / -1;
  }

  .code-actions {
    grid-template-columns: 180px 1fr;
  }

  .preview-stage {
    min-height: 300px;
  }
}

@media (min-width: 960px) {
  .game-grid {
    grid-template-columns: 0.8fr 1.2fr;
  }

  .task-panel,
  .preview-panel,
  .code-panel {
    padding: 28px;
  }
}

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