/* @layer base, components, utilities; */

@layer base {
  :root {
    /* ... (rest of root vars) ... */
    --color-bg-primary: oklch(98% 0.01 240);
    --color-bg-secondary: oklch(96% 0.01 240);
    --color-bg-surface: oklch(100% 0 0);
    
    --color-text-primary: oklch(20% 0.02 240);
    --color-text-secondary: oklch(45% 0.02 240);
    --color-text-tertiary: oklch(70% 0.02 240);
    
    --color-brand-primary: oklch(60% 0.18 250); /* Blue */
    --color-brand-secondary: oklch(65% 0.15 280); /* Purple */
    
    --color-success: oklch(65% 0.15 150);
    --color-warning: oklch(85% 0.15 85);
    --color-danger: oklch(65% 0.2 25);
    --color-info: oklch(85% 0.1 230);

    --border-radius-sm: 8px;
    --border-radius-md: 12px;
    --border-radius-lg: 20px;
    --border-radius-xl: 32px;

    --shadow-sm: 0 2px 4px oklch(0% 0 0 / 5%);
    --shadow-md: 0 10px 25px oklch(0% 0 0 / 8%);
    --shadow-lg: 0 20px 50px oklch(0% 0 0 / 12%);
    
    --font-sans: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
    --font-mono: 'D2Coding', 'Consolas', 'Courier New', monospace;
    
    --app-max-width: 900px;
    --container-padding: 2rem 1rem;
  }

  /* Forced Desktop Mode Styles */
  body.desktop-mode {
    --app-max-width: 1200px;
    min-width: 1024px;
    overflow-x: auto;
  }

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

  body {
    margin: 0;
    padding: 0;
    background-color: var(--color-bg-primary);
    background-image: radial-gradient(at 0% 0%, oklch(95% 0.05 250 / 20%) 0px, transparent 50%),
                      radial-gradient(at 100% 0%, oklch(95% 0.05 280 / 20%) 0px, transparent 50%);
    font-family: var(--font-sans);
    color: var(--color-text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: min-width 0.3s ease;
  }

  @media (max-width: 600px) {
    body:not(.desktop-mode) {
      --container-padding: 1rem 0.5rem;
    }
    
    body:not(.desktop-mode) h1 {
      font-size: 1.4rem !important;
    }
    
    body:not(.desktop-mode) .practice-box {
      padding: 1.2rem;
      min-height: 150px;
    }
    
    body:not(.desktop-mode) #tinner {
      font-size: 1.1rem !important;
    }
    
    body:not(.desktop-mode) #word-q {
      font-size: 1.8rem !important;
    }
  }

  h1, h2, h3, h4 {
    margin: 0;
    font-weight: 700;
  }
}

@layer components {
  /* Layout Containers */
  .container {
    width: 100%;
    max-width: var(--app-max-width);
    margin: 0 auto;
    padding: var(--container-padding);
    flex: 1;
    display: grid;
    grid-template-columns: 1fr;
    gap: clamp(0.5rem, 2vw, 1.5rem);
    transition: all 0.3s ease;
  }

  .app-card {
    background: var(--color-bg-surface);
    border-radius: var(--border-radius-xl);
    padding: clamp(1rem, 5vw, 2.5rem);
    box-shadow: var(--shadow-lg);
    border: 1px solid oklch(100% 0 0 / 50%);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    width: 100%;
    position: relative;
    z-index: 10;
  }

  /* Ad Slots */
  .ad-slot, ad-slot {
    background: var(--color-bg-secondary);
    border: 1px dashed var(--color-text-tertiary);
    border-radius: var(--border-radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0.5rem 0;
    min-height: clamp(80px, 10vh, 120px);
    position: relative;
    overflow: hidden;
    width: 100%;
    flex-shrink: 0;
  }
  
  .ad-slot::after, ad-slot::after {
    content: 'Advertisement';
    font-size: 10px;
    color: var(--color-text-tertiary);
    position: absolute;
    top: 4px;
    right: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
  }

  /* Practice UI Components */
  .practice-box {
    background: var(--color-bg-surface);
    border: 2px solid var(--color-bg-secondary);
    border-radius: var(--border-radius-lg);
    padding: clamp(1rem, 3vw, 2rem);
    min-height: clamp(150px, 20vh, 300px);
    position: relative;
    transition: border-color 0.3s ease;
    width: 100%;
    overflow-wrap: break-word;
  }

  /* Typography & Elements */
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
  }

  /* Re-used from 암기 .html but polished */
  .pill {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 24px;
    background: var(--color-bg-secondary);
    border: 1px solid oklch(0% 0 0 / 5%);
    color: var(--color-text-secondary);
  }

  .btn-base {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--border-radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    font-family: var(--font-sans);
    text-decoration: none;
    font-size: 0.9rem;
  }

  .btn-primary {
    background: var(--color-brand-primary);
    color: white;
    box-shadow: 0 4px 12px oklch(60% 0.18 250 / 30%);
  }
  .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px oklch(60% 0.18 250 / 40%);
  }

  .btn-ghost {
    background: transparent;
    color: var(--color-text-secondary);
  }
  .btn-ghost:hover {
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
  }

  /* Practice UI Components */
  .practice-box {
    background: var(--color-bg-surface);
    border: 2px solid var(--color-bg-secondary);
    border-radius: var(--border-radius-lg);
    padding: 2rem;
    min-height: 200px;
    position: relative;
    transition: border-color 0.3s ease;
  }
  .practice-box:focus-within {
    border-color: var(--color-brand-primary);
  }

  .cur {
    display: inline-block;
    width: 2px;
    height: 1.15em;
    background: var(--color-brand-primary);
    animation: blink 1s step-end infinite;
    vertical-align: text-bottom;
    margin-left: 1px;
  }

  @keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
  @keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
  .shake { animation: shake .3s ease; }

  /* Navigation Bar */
  .nav-bar {
    background: oklch(99% 0.01 240 / 95%);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid oklch(0% 0 0 / 10%);
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
    z-index: 100;
    box-shadow: var(--shadow-sm);
  }

  .logo {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--color-brand-primary), var(--color-brand-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  @media (max-width: 400px) {
    .logo {
      font-size: 1.2rem;
    }
  }

  /* Settings Panel Overlay */
  .settings-overlay {
    position: fixed;
    inset: 0;
    background: oklch(0% 0 0 / 20%);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    justify-content: flex-end;
  }
  .settings-panel {
    background: var(--color-bg-surface);
    width: 100%;
    max-width: 400px;
    height: 100%;
    padding: 2rem;
    box-shadow: -10px 0 50px oklch(0% 0 0 / 10%);
    overflow-y: auto;
    animation: slideIn 0.3s ease-out;
  }
  @keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
}

@layer utilities {
  .mt-1 { margin-top: 0.5rem; }
  .mt-2 { margin-top: 1rem; }
  .mb-1 { margin-bottom: 0.5rem; }
  .mb-2 { margin-bottom: 1rem; }
  .flex-center { display: flex; align-items: center; justify-content: center; }
  .gap-1 { gap: 0.5rem; }
  .gap-2 { gap: 1rem; }
}
