/* =========================================================================
   POLYFIT - Tetromino Puzzle Challenge
   Stylesheet: dark, modern, minimal puzzle-game chrome.
   ========================================================================= */

:root {
  --bg-0: #14141f;
  --bg-1: #1a1a2e;
  --bg-2: #20203a;
  --bg-3: #262646;
  --panel: #22223d;
  --border: #33334f;
  --border-soft: rgba(255, 255, 255, 0.08);
  --text-0: #f5f6ff;
  --text-1: #c7c9e6;
  --text-2: #8d8fb5;
  --accent: #3fd6ff;
  --accent-2: #c07bff;
  --accent-3: #ff5c7a;
  --success: #4dff9e;
  --danger: #ff5c7a;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 18px;
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: radial-gradient(1200px 800px at 15% -10%, #23234a 0%, var(--bg-1) 45%, var(--bg-0) 100%);
  color: var(--text-0);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
}

/* -------------------------------------------------------------------------
   App shell
   ------------------------------------------------------------------------- */

.polyfit-app {
  position: relative;
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.screen {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  animation: pf-fade-in 0.35s ease both;
}

@keyframes pf-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* -------------------------------------------------------------------------
   Buttons
   ------------------------------------------------------------------------- */

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text-0);
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  touch-action: manipulation;
}
.btn:hover { background: var(--bg-3); border-color: #454570; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #10101c;
  box-shadow: 0 6px 20px rgba(63, 214, 255, 0.25);
}
.btn-primary:hover {
  filter: brightness(1.08);
  box-shadow: 0 8px 26px rgba(63, 214, 255, 0.35);
}

.btn-secondary {
  background: var(--bg-3);
  border-color: #3d3d66;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-1);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.06); color: var(--text-0); }

.btn-small { padding: 8px 16px; font-size: 13px; }

.btn-control {
  flex: 1 1 0;
  padding: 10px 12px;
  font-size: 13px;
  border-radius: var(--radius-md);
  background: var(--bg-2);
}
.btn-control:hover { background: var(--bg-3); }

/* -------------------------------------------------------------------------
   Title screen
   ------------------------------------------------------------------------- */

.screen-title {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}

.title-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.pf-logo {
  margin: 0;
  font-size: clamp(48px, 12vw, 96px);
  font-weight: 800;
  letter-spacing: 0.06em;
  background: linear-gradient(135deg, var(--accent) 10%, var(--accent-2) 60%, var(--accent-3) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 30px rgba(192, 123, 255, 0.25));
}

.pf-subtitle {
  margin: 0 0 28px;
  color: var(--text-2);
  font-size: clamp(14px, 2.4vw, 18px);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.title-buttons {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  width: min(320px, 80vw);
}

/* -------------------------------------------------------------------------
   Level select screen
   ------------------------------------------------------------------------- */

.screen-level-select {
  padding: 24px clamp(16px, 5vw, 64px) 48px;
}

.level-select-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.level-select-header h2 {
  margin: 0;
  font-size: 20px;
  color: var(--text-0);
}

.level-select-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}

.level-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  color: var(--text-0);
  cursor: pointer;
  text-align: left;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
}
.level-card:hover { transform: translateY(-2px); border-color: var(--accent); background: var(--bg-3); }
.level-card-num {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
}
.level-card-name {
  font-size: 13px;
  color: var(--text-2);
}
.level-card.completed { border-color: var(--success); }
.level-card.completed .level-card-num { color: var(--success); }
.level-card-check {
  position: absolute;
  top: 10px;
  right: 12px;
  color: var(--success);
  font-weight: 700;
}
.level-card-tag {
  margin-top: 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-2);
  background: rgba(192, 123, 255, 0.12);
  padding: 2px 8px;
  border-radius: 999px;
}

/* -------------------------------------------------------------------------
   Game screen
   ------------------------------------------------------------------------- */

.screen-game {
  padding: 0;
}

.game-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--border-soft);
  background: rgba(20, 20, 31, 0.6);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.pf-logo-small {
  font-weight: 800;
  letter-spacing: 0.06em;
  font-size: 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.level-info {
  flex: 1;
  min-width: 0;
}
.level-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
}
.level-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.game-main {
  flex: 1;
  display: flex;
  gap: 20px;
  padding: 20px clamp(16px, 3vw, 32px) 8px;
  align-items: stretch;
}

.board-panel {
  flex: 1 1 65%;
  display: flex;
  min-height: 420px;
}

.board-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 10px;
  position: relative;
  min-height: 380px;
  transition: box-shadow 0.2s ease;
}

#pf-board-canvas {
  touch-action: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.board-wrapper.shake { animation: pf-shake 0.35s ease; }
@keyframes pf-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.tray-panel {
  flex: 1 1 35%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 18px;
}

.tray-title {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
}

.tray-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 90px;
  align-content: flex-start;
}

.tray-piece {
  appearance: none;
  background: var(--bg-2);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
  touch-action: none;
}
.tray-piece:hover { border-color: #4c4c78; transform: translateY(-1px); }
.tray-piece:active { cursor: grabbing; }
.tray-piece.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(63, 214, 255, 0.25), 0 0 18px rgba(63, 214, 255, 0.3);
}

.controls {
  border-top: 1px solid var(--border-soft);
  padding-top: 14px;
}
.controls h4 {
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
}
.control-buttons {
  display: flex;
  gap: 8px;
}
.control-hints {
  margin: 10px 0 0;
  font-size: 11px;
  color: var(--text-2);
  line-height: 1.5;
}

.progress-info {
  margin-top: auto;
  font-size: 13px;
  color: var(--text-1);
  text-align: center;
  padding-top: 10px;
  border-top: 1px solid var(--border-soft);
}

/* -------------------------------------------------------------------------
   Tutorial hint footer
   ------------------------------------------------------------------------- */

.hint-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px clamp(16px, 3vw, 32px) 20px;
  padding: 14px 18px;
  background: linear-gradient(135deg, rgba(63, 214, 255, 0.14), rgba(192, 123, 255, 0.14));
  border: 1px solid rgba(63, 214, 255, 0.35);
  border-radius: var(--radius-md);
  position: relative;
  animation: pf-banner-in 0.3s ease both;
}
.hint-footer::before {
  content: "";
  position: absolute;
  top: -8px;
  left: 28px;
  width: 14px;
  height: 14px;
  background: inherit;
  border-left: 1px solid rgba(63, 214, 255, 0.35);
  border-top: 1px solid rgba(63, 214, 255, 0.35);
  transform: rotate(45deg);
}
@keyframes pf-banner-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.hint-footer-text {
  flex: 1;
  font-size: 14px;
  color: var(--text-0);
}
.hint-dismiss {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-1);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
.hint-dismiss:hover { background: rgba(255, 255, 255, 0.1); color: var(--text-0); }

/* tutorial target glow */
.tutorial-glow {
  animation: pf-pulse-glow 1.6s ease-in-out infinite;
  border-radius: var(--radius-lg);
}
@keyframes pf-pulse-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(63, 214, 255, 0.55); }
  50% { box-shadow: 0 0 0 8px rgba(63, 214, 255, 0); }
}

/* -------------------------------------------------------------------------
   Level complete overlay
   ------------------------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 18, 0.7);
  backdrop-filter: blur(4px);
  z-index: 50;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.overlay.show { opacity: 1; }
.overlay[hidden] { display: none; }

.overlay-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 48px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  transform: scale(0.92);
  transition: transform 0.25s ease;
  max-width: 90vw;
}
.overlay.show .overlay-panel { transform: scale(1); }

.overlay-panel h2 {
  margin: 0 0 10px;
  font-size: 28px;
  background: linear-gradient(135deg, var(--accent), var(--success));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.overlay-stats {
  margin: 0 0 24px;
  color: var(--text-1);
  font-size: 14px;
}

/* -------------------------------------------------------------------------
   Drag ghost
   ------------------------------------------------------------------------- */

.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 1000;
  opacity: 0.9;
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.5));
}
.drag-ghost[hidden] { display: none; }

/* -------------------------------------------------------------------------
   Responsive
   ------------------------------------------------------------------------- */

@media (max-width: 900px) {
  .tray-panel { max-width: 280px; }
}

@media (max-width: 600px) {
  .game-main {
    flex-direction: column;
    padding: 14px 12px 4px;
  }
  .board-panel { min-height: 320px; }
  .tray-panel { max-width: none; }
  .title-buttons { width: 90vw; }
  .overlay-panel { padding: 28px 24px; }
  .game-header { gap: 10px; }
  .level-name { max-width: 45vw; }
}

@media (max-width: 380px) {
  .control-buttons { flex-wrap: wrap; }
  .btn-control { flex: 1 1 45%; }
}
