/* ===== Kathyz M3 Design System ===== */
@import url('https://fonts.googleapis.com/css2?family=Kumbh+Sans:wght@400;500;600;700;800&display=swap');

:root {
  --md-sys-color-primary: #D0BCFF;
  --md-sys-color-on-primary: #381E72;
  --md-sys-color-primary-container: #4F378B;
  --md-sys-color-on-primary-container: #EADDFF;

  --md-sys-color-secondary: #CCC2DC;
  --md-sys-color-on-secondary: #332D41;
  --md-sys-color-secondary-container: #4A4458;
  --md-sys-color-on-secondary-container: #E8DEF8;

  --md-sys-color-tertiary: #EFB8C8;
  --md-sys-color-on-tertiary: #492532;
  --md-sys-color-tertiary-container: #633B48;
  --md-sys-color-on-tertiary-container: #FFD8E4;

  --md-sys-color-error: #F2B8B5;
  --md-sys-color-on-error: #601410;
  --md-sys-color-error-container: #8C1D18;
  --md-sys-color-on-error-container: #F9DEDC;

  --md-sys-color-surface: #141218;
  --md-sys-color-on-surface: #E6E0E9;
  --md-sys-color-surface-variant: #49454F;
  --md-sys-color-on-surface-variant: #CAC4D0;
  --md-sys-color-surface-container: #211F26;
  --md-sys-color-surface-container-high: #2B2930;
  --md-sys-color-surface-container-highest: #36343B;
  --md-sys-color-surface-container-low: #1D1B20;
  --md-sys-color-surface-container-lowest: #0F0D13;
  --md-sys-color-background: #141218;
  --md-sys-color-on-background: #E6E0E9;
  --md-sys-color-outline: #938F99;
  --md-sys-color-outline-variant: #49454F;
  --md-sys-color-shadow: #000000;

  --md-shape-xs: 4px;
  --md-shape-sm: 8px;
  --md-shape-md: 12px;
  --md-shape-lg: 16px;
  --md-shape-xl: 20px;
  --md-shape-full: 9999px;

  --md-elevation-1: 0 1px 3px 1px rgba(0,0,0,.15), 0 1px 2px 0 rgba(0,0,0,.3);
  --md-elevation-2: 0 2px 6px 2px rgba(0,0,0,.15), 0 1px 2px 0 rgba(0,0,0,.3);
  --md-elevation-3: 0 4px 8px 3px rgba(0,0,0,.15), 0 1px 3px 0 rgba(0,0,0,.3);
  --md-elevation-4: 0 6px 10px 4px rgba(0,0,0,.15), 0 2px 3px 0 rgba(0,0,0,.3);
  --md-elevation-5: 0 8px 12px 6px rgba(0,0,0,.15), 0 4px 4px 0 rgba(0,0,0,.3);

  --md-font: 'Kumbh Sans', 'Google Sans', system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--md-font);
  background: var(--md-sys-color-background);
  color: var(--md-sys-color-on-surface);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

.material-symbols-rounded {
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  font-size: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.m3-top-bar {
  display: flex;
  align-items: center;
  height: 64px;
  padding: 0 16px;
  background: var(--md-sys-color-surface-container);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 12px;
}

.m3-top-bar-leading { display: flex; align-items: center; color: var(--md-sys-color-primary); }

.m3-top-bar-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
  flex: 1;
  letter-spacing: -0.25px;
}

.m3-top-bar-trailing { display: flex; gap: 4px; }

.m3-icon-btn {
  width: 40px; height: 40px;
  border: none; border-radius: var(--md-shape-full);
  background: transparent; color: var(--md-sys-color-on-surface-variant);
  cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  transition: all .15s;
}

.m3-icon-btn:hover { background: color-mix(in srgb, var(--md-sys-color-primary) 12%, transparent); color: var(--md-sys-color-primary); }

.page { display: none; padding: 16px; flex: 1; max-width: 960px; margin: 0 auto; width: 100%; padding-bottom: 88px; }
.page.active { display: block; }

.m3-display-large {
  font-size: 57px; font-weight: 800; line-height: 1.12; letter-spacing: -0.25px;
  background: linear-gradient(135deg, var(--md-sys-color-primary), var(--md-sys-color-tertiary));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

.m3-headline-medium { font-size: 28px; font-weight: 700; line-height: 1.2; color: var(--md-sys-color-on-surface); }
.m3-title-medium { font-size: 16px; font-weight: 600; line-height: 1.5; letter-spacing: 0.15px; }
.m3-body-medium { font-size: 14px; font-weight: 400; line-height: 1.5; letter-spacing: 0.25px; }
.m3-body-small { font-size: 12px; font-weight: 400; line-height: 1.5; letter-spacing: 0.4px; }
.m3-on-surface-variant { color: var(--md-sys-color-on-surface-variant); }

.m3-hero { text-align: center; padding: 40px 16px 32px; display: flex; flex-direction: column; align-items: center; gap: 16px; }

.m3-hero-badge {
  display: inline-flex; padding: 4px 16px; border-radius: var(--md-shape-full);
  background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container);
  font-size: 13px; font-weight: 600; letter-spacing: 0.5px;
}

.m3-hero p { color: var(--md-sys-color-on-surface-variant); max-width: 360px; }

.m3-hero-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }

.m3-fab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 24px; border: none; border-radius: var(--md-shape-lg);
  background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container);
  font-family: var(--md-font); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all .15s; box-shadow: var(--md-elevation-3); letter-spacing: 0.5px;
}

.m3-fab:hover { box-shadow: var(--md-elevation-4); transform: translateY(-1px); }
.m3-fab:active { transform: translateY(0); box-shadow: var(--md-elevation-2); }
.m3-fab-small { padding: 8px 20px; border-radius: var(--md-shape-full); }

.m3-tonal-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 24px; border: none; border-radius: var(--md-shape-full);
  background: var(--md-sys-color-surface-container-high); color: var(--md-sys-color-primary);
  font-family: var(--md-font); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all .15s; letter-spacing: 0.5px;
}

.m3-tonal-btn:hover { background: var(--md-sys-color-surface-container-highest); }

.m3-features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 8px; }

.m3-card-elevated {
  background: var(--md-sys-color-surface-container-low); border-radius: var(--md-shape-md);
  padding: 24px 16px; display: flex; flex-direction: column;
  align-items: center; text-align: center; gap: 8px;
  box-shadow: var(--md-elevation-1); border: 1px solid var(--md-sys-color-outline-variant);
}

.m3-card-icon {
  width: 48px; height: 48px; border-radius: var(--md-shape-full);
  background: var(--md-sys-color-primary-container); color: var(--md-sys-color-primary);
  display: flex; align-items: center; justify-content: center; margin-bottom: 4px;
}

.m3-card-elevated { transition: all .2s; cursor: pointer; }
.m3-card-elevated:hover { border-color: var(--md-sys-color-primary); box-shadow: var(--md-elevation-3); }
.m3-card-elevated h3 { color: var(--md-sys-color-on-surface); }
.m3-card-elevated p { color: var(--md-sys-color-on-surface-variant); }
.m3-features-custom { grid-template-columns: repeat(4, 1fr); margin-top: 16px; }
.m3-custom-game { padding: 16px 12px; }
.m3-custom-game:hover { transform: translateY(-2px); }

.m3-search-field {
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px; height: 48px;
  border: 1px solid var(--md-sys-color-outline); border-radius: var(--md-shape-sm);
  background: transparent; margin: 16px 0; transition: border-color .15s;
}

.m3-search-field:focus-within { border-color: var(--md-sys-color-primary); border-width: 2px; padding: 0 15px; }
.m3-search-field span { color: var(--md-sys-color-on-surface-variant); }
.m3-search-field:focus-within span { color: var(--md-sys-color-primary); }
.m3-search-field input {
  flex: 1; height: 100%; background: transparent; border: none; outline: none;
  color: var(--md-sys-color-on-surface); font-family: var(--md-font); font-size: 16px; letter-spacing: 0.5px;
}
.m3-search-field input::placeholder { color: var(--md-sys-color-outline); }

.m3-category-bar {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px;
  padding-bottom: 8px; overflow-x: auto;
}

.m3-cat-btn {
  padding: 6px 14px; border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-full); background: transparent;
  color: var(--md-sys-color-on-surface-variant); font-family: var(--md-font);
  font-size: 13px; font-weight: 500; cursor: pointer; transition: all .15s;
  white-space: nowrap;
}

.m3-cat-btn:hover { border-color: var(--md-sys-color-primary); color: var(--md-sys-color-primary); }
.m3-cat-btn.active { background: var(--md-sys-color-primary-container); border-color: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary-container); }

.m3-games-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px; margin-bottom: 16px;
}

.m3-game-card {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 16px 12px; border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-md); background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface); font-family: var(--md-font); cursor: pointer;
  transition: all .2s; box-shadow: var(--md-elevation-1); text-align: center;
}

.m3-game-card:hover {
  border-color: var(--md-sys-color-primary); box-shadow: var(--md-elevation-3);
  transform: translateY(-2px); background: var(--md-sys-color-surface-container);
}

.m3-game-emoji { font-size: 32px; line-height: 1; }
.m3-game-card .m3-body-small { color: var(--md-sys-color-on-surface-variant); }

.m3-tab-bar {
  position: fixed; top: 64px; left: 0; right: 0; z-index: 99;
  background: var(--md-sys-color-surface-container); border-bottom: 1px solid var(--md-sys-color-outline-variant);
  padding: 4px 8px; overflow-x: auto; display: none;
}

.m3-tab-scroll { display: flex; gap: 4px; }

.m3-tab-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-sm); background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface-variant); font-family: var(--md-font);
  font-size: 13px; cursor: pointer; transition: all .15s; white-space: nowrap;
}

.m3-tab-btn.active { background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); border-color: var(--md-sys-color-primary); }
.m3-tab-close { font-size: 16px; line-height: 1; cursor: pointer; opacity: .6; }
.m3-tab-close:hover { opacity: 1; }

#embed-container { position: fixed; top: 108px; left: 0; right: 0; bottom: 64px; z-index: 50; pointer-events: none; }

.m3-embed {
  width: 100%; height: 100%; border: none; display: none;
  background: var(--md-sys-color-background); pointer-events: auto;
}

.m3-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.6); z-index: 200;
  align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}

.m3-overlay.active { display: flex; }

.m3-overlay-surface {
  background: var(--md-sys-color-surface-container-high); border-radius: var(--md-shape-xl);
  padding: 24px; max-width: 560px; width: 92%;
  max-height: 90vh; overflow-y: auto; position: relative;
  box-shadow: var(--md-elevation-5);
  animation: m3-scaleIn .2s cubic-bezier(0,0,.2,1);
}

@keyframes m3-scaleIn { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.m3-overlay-close { position: absolute; top: 8px; right: 8px; z-index: 10; background: var(--md-sys-color-surface-container); border-radius: var(--md-shape-full); }
.m3-overlay-close:hover { background: var(--md-sys-color-surface-container-highest); }

.m3-footer { display: none; align-items: center; justify-content: center; gap: 8px; padding: 16px; color: var(--md-sys-color-outline); font-size: 13px; border-top: 1px solid var(--md-sys-color-surface-container-high); }

.m3-nav-bar {
  display: flex; align-items: center; justify-content: space-around;
  height: 64px; background: var(--md-sys-color-surface-container);
  border-top: 1px solid var(--md-sys-color-surface-container-high);
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
}

.m3-nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 16px; border: none; background: transparent;
  color: var(--md-sys-color-on-surface-variant); font-family: var(--md-font);
  cursor: pointer; transition: all .15s; border-radius: var(--md-shape-sm); min-width: 64px;
}

.m3-nav-item:hover { background: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent); }
.m3-nav-item.active { color: var(--md-sys-color-primary); }
.m3-nav-item.active .material-symbols-rounded { font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24; }
.m3-nav-label { font-size: 12px; font-weight: 500; letter-spacing: 0.5px; }

.m3-proxy-form { display: flex; gap: 8px; margin: 16px 0; }

.m3-outlined-field {
  flex: 1; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-shape-sm); background: transparent; transition: border-color .15s;
}

.m3-outlined-field:focus-within { border-color: var(--md-sys-color-primary); border-width: 2px; padding: 0 15px; }

.m3-field-leading { color: var(--md-sys-color-on-surface-variant); font-size: 20px; }
.m3-outlined-field:focus-within .m3-field-leading { color: var(--md-sys-color-primary); }

.m3-outlined-field input {
  flex: 1; height: 48px; background: transparent; border: none; outline: none;
  color: var(--md-sys-color-on-surface); font-family: var(--md-font); font-size: 16px; letter-spacing: 0.5px;
}
.m3-outlined-field input::placeholder { color: var(--md-sys-color-outline); }

.m3-shortcuts { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

.m3-shortcut {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-full); background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface); font-family: var(--md-font);
  font-size: 13px; cursor: pointer; transition: all .15s;
}

.m3-shortcut:hover { border-color: var(--md-sys-color-primary); background: var(--md-sys-color-surface-container); }

.m3-shortcut-icon {
  width: 24px; height: 24px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 13px; font-weight: 700;
}

#proxy-output {
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-md);
  min-height: 480px; overflow: hidden;
}

#proxy-output iframe { width: 100%; height: 100%; border: none; min-height: 480px; display: block; }

.m3-proxy-placeholder {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px; min-height: 480px; color: var(--md-sys-color-on-surface-variant);
}

.m3-placeholder-icon { font-size: 48px !important; color: var(--md-sys-color-outline); }

#game-frame { min-height: 360px; }

.game-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; padding: 0 4px; }

.game-score { font-size: 14px; font-weight: 600; color: var(--md-sys-color-on-surface-variant); display: flex; align-items: center; gap: 4px; }
.game-score span { color: var(--md-sys-color-primary); font-weight: 700; }
.game-controls { margin-top: 12px; display: flex; gap: 8px; justify-content: center; }

#snake-game { text-align: center; }
#snake-canvas { background: var(--md-sys-color-surface-container-lowest); border: 1px solid var(--md-sys-color-outline-variant); border-radius: var(--md-shape-sm); display: block; margin: 0 auto; max-width: 100%; }

#tictactoe-game { text-align: center; }
.ttt-board { display: grid; grid-template-columns: repeat(3, 96px); gap: 6px; justify-content: center; margin: 12px auto; }
.ttt-cell { width: 96px; height: 96px; background: var(--md-sys-color-surface-container-lowest); border: 1px solid var(--md-sys-color-outline-variant); border-radius: var(--md-shape-sm); display: flex; align-items: center; justify-content: center; font-size: 2.5rem; cursor: pointer; transition: all .15s; color: var(--md-sys-color-on-surface); font-weight: 700; }
.ttt-cell:hover { border-color: var(--md-sys-color-primary); background: color-mix(in srgb, var(--md-sys-color-primary) 6%, transparent); }
.ttt-cell.x { color: var(--md-sys-color-primary); }
.ttt-cell.o { color: var(--md-sys-color-tertiary); }
.ttt-status { font-size: 15px; font-weight: 600; margin: 12px 0; color: var(--md-sys-color-on-surface-variant); }

#memory-game { text-align: center; }
.memory-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; max-width: 360px; margin: 12px auto; }
.memory-card { aspect-ratio: 1; background: var(--md-sys-color-primary-container); border-radius: var(--md-shape-sm); display: flex; align-items: center; justify-content: center; font-size: 1.8rem; cursor: pointer; transition: all .25s cubic-bezier(0,0,.2,1); user-select: none; box-shadow: var(--md-elevation-1); }
.memory-card.flipped { background: var(--md-sys-color-surface-container-lowest); border: 1px solid var(--md-sys-color-primary); box-shadow: var(--md-elevation-2); }
.memory-card.matched { background: var(--md-sys-color-secondary-container); border: 1px solid var(--md-sys-color-secondary); cursor: default; }

#clicker-game { text-align: center; }
.clicker-area { background: var(--md-sys-color-surface-container-lowest); border: 1px solid var(--md-sys-color-outline-variant); border-radius: var(--md-shape-lg); padding: 32px; cursor: pointer; transition: all .1s; margin: 12px auto; max-width: 360px; user-select: none; position: relative; overflow: hidden; }
.clicker-area:active { transform: scale(.97); }
.clicker-score { font-size: 56px; font-weight: 800; color: var(--md-sys-color-primary); line-height: 1; letter-spacing: -1px; }
.clicker-multiplier { font-size: 15px; color: var(--md-sys-color-tertiary); margin-top: 8px; font-weight: 600; }
.clicker-upgrades { display: flex; gap: 8px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.upgrade-btn { background: var(--md-sys-color-surface-container); color: var(--md-sys-color-primary); border: 1px solid var(--md-sys-color-outline-variant); padding: 8px 16px; border-radius: var(--md-shape-sm); font-family: var(--md-font); font-size: 13px; font-weight: 600; cursor: pointer; transition: all .15s; }
.upgrade-btn:hover { background: var(--md-sys-color-surface-container-high); border-color: var(--md-sys-color-primary); }
.upgrade-btn:disabled { opacity: .35; cursor: default; }

.m3-main-fab {
  position: fixed; bottom: 80px; right: 16px; z-index: 90;
}

@media (max-width: 640px) {
  .m3-top-bar { height: 56px; padding: 0 12px; }
  .m3-top-bar-title { font-size: 20px; }
  .m3-top-bar-trailing { display: none; }
  .m3-display-large { font-size: 40px; }
  .m3-hero { padding: 24px 8px; }
  .m3-features { grid-template-columns: 1fr; }
  .m3-features-custom { grid-template-columns: repeat(2, 1fr); }
  .m3-games-grid { grid-template-columns: repeat(2, 1fr); }
  .m3-game-card { padding: 12px 8px; }
  .m3-game-emoji { font-size: 28px; }
  .memory-grid { max-width: 300px; gap: 6px; }
  .ttt-board { grid-template-columns: repeat(3, 80px); }
  .ttt-cell { width: 80px; height: 80px; }
  .m3-proxy-form { flex-direction: column; }
  .m3-fab-small { align-self: flex-end; }
  .m3-tab-bar { top: 56px; }
  #embed-container { top: 100px; }
}

@media (min-width: 641px) {
  .m3-nav-bar { display: none; }
  .m3-footer { display: flex; }
  .page { padding-bottom: 16px; }
}
