/* ==========================================================================
   TACTILE CLAYFORGE - CORE STYLES & DESIGN SYSTEM
   ========================================================================== */

:root {
  --bg-dark: #0d0f18;
  --bg-panel: rgba(22, 26, 42, 0.85);
  --bg-panel-solid: #161a2a;
  --bg-card: #1d2238;
  --border-light: rgba(255, 255, 255, 0.12);
  --border-accent: rgba(224, 109, 83, 0.4);

  --color-terracotta: #e06d53;
  --color-terracotta-glow: #ff8c69;
  --color-teal: #3ecf8e;
  --color-teal-glow: #64e5ab;
  --color-ice: #4cc9f0;
  --color-gold: #ffd166;
  --color-danger: #ff5252;

  --text-main: #f0f3fa;
  --text-muted: #9aa3c0;

  --font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  --glass-backdrop: blur(12px) saturate(160%);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-family);
  touch-action: none;
}

#app-container {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  position: relative;
  background: radial-gradient(circle at 50% 30%, #1a2035 0%, #0d0f18 100%);
}

/* --------------------------------------------------------------------------
   HEADER
   -------------------------------------------------------------------------- */
#game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--bg-panel);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  border-bottom: 1px solid var(--border-light);
  z-index: 10;
  height: 64px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-logo {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.4));
}

.title-wrap {
  display: flex;
  flex-direction: column;
}

.app-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, #ffffff 0%, #d0d7ed 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.level-subtitle {
  font-size: 0.78rem;
  color: var(--color-terracotta-glow);
  font-weight: 500;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.metric-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.35);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border-light);
}

.metric-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}

.metric-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-teal);
  min-width: 40px;
  text-align: right;
}

/* --------------------------------------------------------------------------
   WORKBENCH & CANVAS
   -------------------------------------------------------------------------- */
#workbench-area {
  flex: 1;
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.instruction-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(13, 15, 24, 0.85);
  backdrop-filter: var(--glass-backdrop);
  border: 1px solid var(--border-accent);
  padding: 8px 18px;
  border-radius: 30px;
  font-size: 0.85rem;
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
  z-index: 5;
  pointer-events: none;
  text-align: center;
  max-width: 90%;
}

.toast-message {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(224, 109, 83, 0.92);
  color: #ffffff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 15;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.toast-message.hidden {
  opacity: 0;
  transform: translate(-50%, 15px);
}

/* --------------------------------------------------------------------------
   FOOTER & TOOL PALETTE
   -------------------------------------------------------------------------- */
#game-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px 16px;
  background: var(--bg-panel);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  border-top: 1px solid var(--border-light);
  z-index: 10;
}

.tool-palette {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

.tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1.5px solid var(--border-light);
  padding: 10px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
  min-height: 48px;
}

.tool-btn:hover {
  background: #252b45;
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.25);
}

.tool-btn.active {
  background: linear-gradient(135deg, rgba(224, 109, 83, 0.25) 0%, rgba(255, 140, 105, 0.1) 100%);
  border-color: var(--color-terracotta-glow);
  color: #ffffff;
  box-shadow: 0 0 16px rgba(224, 109, 83, 0.3);
}

.tool-btn[data-tool="freeze"].active {
  background: linear-gradient(135deg, rgba(76, 201, 240, 0.25) 0%, rgba(76, 201, 240, 0.1) 100%);
  border-color: var(--color-ice);
  box-shadow: 0 0 16px rgba(76, 201, 240, 0.3);
}

.tool-icon {
  font-size: 1.25rem;
}

.tool-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.1;
}

.tool-name {
  font-size: 0.82rem;
  font-weight: 700;
}

.tool-sub {
  font-size: 0.68rem;
  opacity: 0.7;
}

.action-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* BUTTON SYSTEM */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  min-height: 44px;
}

.btn-icon {
  padding: 8px 12px;
  background: var(--bg-card);
  border-color: var(--border-light);
  color: var(--text-main);
}

.btn-icon:hover {
  background: #282f4c;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-light);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-terracotta) 0%, #b8462b 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(224, 109, 83, 0.4);

  flex: 1;
}

.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 6px 18px rgba(224, 109, 83, 0.6);
}

.btn-success {
  background: linear-gradient(135deg, var(--color-teal) 0%, #109856 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(62, 207, 142, 0.4);
  flex: 1;
}

.btn-success:hover {
  filter: brightness(1.1);
  box-shadow: 0 6px 18px rgba(62, 207, 142, 0.6);
}

.hidden {
  display: none !important;
}

/* --------------------------------------------------------------------------
   MODALS
   -------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 18, 0.8);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn 0.25s ease;
}

.modal-content {
  background: var(--bg-panel-solid);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.8rem;
  cursor: pointer;
  line-height: 1;
}

.btn-close:hover {
  color: var(--text-main);
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.stage-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stage-card:hover {
  border-color: var(--color-teal);
  transform: translateY(-2px);
}

.stage-card.active-stage {
  border-color: var(--color-terracotta);
  background: rgba(224, 109, 83, 0.15);
}

.stage-card-num {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.stage-card-title {
  font-size: 0.95rem;
  font-weight: 700;
}

/* VICTORY MODAL */
.victory-content {
  text-align: center;
  align-items: center;
}

.victory-icon {
  font-size: 3.5rem;
}

.star-rating {
  display: flex;
  gap: 8px;
  font-size: 2.2rem;
  color: rgba(255, 255, 255, 0.2);
}

.star.earned {
  color: var(--color-gold);
  text-shadow: 0 0 12px rgba(255, 209, 102, 0.6);
}

.victory-desc {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.modal-actions {
  display: flex;
  gap: 12px;
  width: 100%;
  margin-top: 10px;
}

/* --------------------------------------------------------------------------
   RESPONSIVE LAYOUT BREAKPOINTS
   -------------------------------------------------------------------------- */
@media (max-width: 600px) {
  #game-header {
    padding: 8px 12px;
  }
  .app-title {
    font-size: 1rem;
  }
  .btn-text {
    display: none;
  }
  .tool-sub {
    display: none;
  }
  .tool-btn {
    padding: 8px;
    min-height: 44px;
  }
  .tool-name {
    font-size: 0.75rem;
  }
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}
