:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a24;
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.7);
  --text-muted: rgba(255, 255, 255, 0.5);
  --border-color: rgba(255, 255, 255, 0.08);
  --accent: #1abc9c;
  --accent-gradient: linear-gradient(135deg, #1abc9c, #3498db);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --transition: all 0.2s ease;
  --header-height: 60px;
  --footer-height: 40px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overscroll-behavior: none;
}

/* ===== APP LAYOUT (flex column: header / canvas / keyboard / footer) ===== */
body {
  display: flex;
  flex-direction: column;
}

/* ===== HEADER ===== */
.app-header {
  flex-shrink: 0;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: rgba(10, 10, 15, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.logo-icon {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--accent);
  background: rgba(26, 188, 156, 0.15);
  border-radius: 50%;
  border: 1px solid rgba(26, 188, 156, 0.3);
  animation: logoPulse 3s ease-in-out infinite;
}

@keyframes logoPulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(26, 188, 156, 0.3);
  }
  50% {
    box-shadow: 0 0 20px 2px rgba(26, 188, 156, 0.3);
  }
}

.logo-text {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.control-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
}

.control-btn:active {
  transform: scale(0.92);
}

.control-btn .icon {
  width: 20px;
  height: 20px;
}

.control-btn.active {
  color: var(--accent);
  border-color: rgba(26, 188, 156, 0.4);
  background: rgba(26, 188, 156, 0.1);
}

.control-btn.muted {
  color: #e74c3c;
  border-color: rgba(231, 76, 60, 0.4);
  background: rgba(231, 76, 60, 0.1);
}

.control-btn.muted svg path:last-child,
.control-btn.muted svg path:nth-last-child(2) {
  opacity: 0.3;
}

.control-btn.muted::after {
  content: "";
  position: absolute;
  width: 2px;
  height: 24px;
  background: #e74c3c;
  border-radius: 2px;
  transform: rotate(45deg);
  pointer-events: none;
}

/* ===== CANVAS ===== */
.canvas-wrapper {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

canvas#myCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse at center, #14141f 0%, #0a0a0f 100%);
  display: block;
}

/* ===== KEYBOARD ===== */
.keyboard-container {
  flex-shrink: 0;
  background: rgba(10, 10, 15, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-color);
  padding: 10px 12px;
  z-index: 50;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.keyboard-container.hidden {
  display: none;
}

.keyboard {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.key-row {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.key-cap {
  flex: 1;
  max-width: 72px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Inter", sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  touch-action: manipulation;
}

.key-cap::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--key-color, var(--accent));
  opacity: 0;
  transition: opacity 0.15s ease;
}

.key-cap:hover {
  border-color: var(--key-color, var(--accent));
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-1px);
}

.key-cap:active,
.key-cap.active {
  border-color: var(--key-color, var(--accent));
  color: #fff;
  transform: scale(0.92);
}

.key-cap:active::after,
.key-cap.active::after {
  opacity: 0.25;
}

/* ===== FOOTER ===== */
.app-footer {
  flex-shrink: 0;
  height: var(--footer-height);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 15, 0.95);
  border-top: 1px solid var(--border-color);
  font-size: 0.8rem;
  color: var(--text-muted);
  z-index: 100;
}

.app-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.app-footer a:hover {
  color: #fff;
}

/* ===== OVERLAYS ===== */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 5, 10, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 200;
  padding: 20px;
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  max-width: 420px;
  width: 100%;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  text-align: center;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 40px 32px;
  box-shadow: var(--shadow);
  animation: overlayIn 0.3s ease;
}

@keyframes overlayIn {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.overlay-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: var(--accent);
  background: rgba(26, 188, 156, 0.12);
  border: 2px solid rgba(26, 188, 156, 0.3);
  border-radius: 50%;
  animation: logoPulse 3s ease-in-out infinite;
}

.overlay-content h2 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 12px;
  letter-spacing: -0.5px;
}

.overlay-text {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 8px;
}

.overlay-text strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* ===== PRIMARY BUTTON ===== */
.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 20px;
  padding: 12px 36px;
  font-family: "Inter", sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent-gradient);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 20px rgba(26, 188, 156, 0.35);
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px rgba(26, 188, 156, 0.5);
}

.primary-btn:active {
  transform: scale(0.96);
}

/* ===== HELP ===== */
.help-items {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 24px 0;
  text-align: left;
}

.help-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.help-key {
  flex-shrink: 0;
  min-width: 52px;
  text-align: center;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
}

/* ===== RESPONSIVE ===== */

/* Tablets & small desktops */
@media (max-width: 900px) {
  .keyboard {
    max-width: 100%;
  }

  .key-cap {
    max-width: 60px;
    height: 38px;
    font-size: 0.85rem;
  }
}

/* Mobile landscape - shorter UI */
@media (max-height: 500px) {
  :root {
    --header-height: 48px;
    --footer-height: 30px;
  }

  .app-header {
    padding: 0 12px;
  }

  .keyboard-container {
    padding: 6px 8px;
  }

  .key-cap {
    height: 28px;
    font-size: 0.72rem;
  }

  .overlay-content {
    padding: 24px 20px;
  }

  .overlay-logo {
    width: 48px;
    height: 48px;
    font-size: 24px;
    margin-bottom: 12px;
  }

  .overlay-content h2 {
    font-size: 1.4rem;
  }
}

/* Mobile portrait */
@media (max-width: 600px) {
  :root {
    --header-height: 52px;
    --footer-height: 34px;
  }

  .app-header {
    padding: 0 12px;
  }

  .logo-text {
    font-size: 1.1rem;
  }

  .logo-icon {
    width: 30px;
    height: 30px;
    font-size: 17px;
  }

  .control-btn {
    width: 36px;
    height: 36px;
  }

  .control-btn .icon {
    width: 18px;
    height: 18px;
  }

  .keyboard-container {
    padding: 8px 6px;
  }

  .keyboard {
    gap: 4px;
  }

  .key-row {
    gap: 4px;
  }

  .key-cap {
    max-width: 52px;
    height: 36px;
    font-size: 0.8rem;
    border-radius: 6px;
  }

  .overlay-content {
    padding: 32px 20px;
    border-radius: 16px;
  }

  .overlay-content h2 {
    font-size: 1.5rem;
  }

  .app-footer {
    font-size: 0.7rem;
  }
}

/* Very small devices */
@media (max-width: 400px) {
  .key-cap {
    height: 34px;
    font-size: 0.72rem;
  }

  .key-row {
    gap: 3px;
  }

  .keyboard {
    gap: 3px;
  }
}

/* Touch devices - larger tap targets */
@media (pointer: coarse) {
  .key-cap {
    min-height: 44px;
  }

  .control-btn {
    width: 44px;
    height: 44px;
  }
}

/* ===== ANIMATION UTILITIES ===== */
.animated {
  animation-duration: 0.4s;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-color);
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== FOCUS STATES ===== */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
