@tailwind base;
@tailwind components;
@tailwind utilities;

@font-face {
  font-family: 'T-Star';
  src: url('../fonts/T-Star-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'T-Star';
  src: url('../fonts/T-Star-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'T-Star';
  src: url('../fonts/T-Star-Heavy.woff2') format('woff2');
  font-weight: 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --color-success: #10b981;
  --color-surface: #09090b;
  --color-text: #fafafa;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 16px;
  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 16px;
  --sp-lg: 24px;
  --sp-xl: 32px;
  --sp-2xl: 48px;
  --font-sans: 'T-Star', system-ui, sans-serif;
  --font-mono: 'T-Star', monospace;
  --bg-page: #f1f1f3;
  --bg-surface: #ffffff;
  --bg-panel: #f6f6f7;
  --border-subtle: #e4e4e7;
  --border-strong: #d1d1d6;
  --text-primary: #18181b;
  --text-secondary: #6b7280;
  --text-muted: #a1a1aa;
  --bg-topbar: rgba(255, 255, 255, 0.92);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.07), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.07);
}

.dark {
  --bg-page: #09090b;
  --bg-surface: #111113;
  --bg-panel: rgba(255, 255, 255, 0.03);
  --border-subtle: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.13);
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #52525b;
  --bg-topbar: rgba(9, 9, 11, 0.92);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.5);
}

@layer base {
  html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-size: 16px;
  }

  body {
    font-family: var(--font-sans);
    font-weight: 400;
    background: var(--bg-page);
    color: var(--text-primary);
    transition: background 0.2s, color 0.2s;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    margin: 0;
  }

  h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-sans);
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: -0.03em;
  }

  h1 {
    font-size: 1.875rem;
    line-height: 1.15;
  }

  h2 {
    font-size: 1.5rem;
    line-height: 1.2;
  }

  h3 {
    font-size: 1.25rem;
    line-height: 1.25;
  }

  @media (max-width: 1024px) {
    h1 { font-size: 1.5rem; }
  }

  @media (max-width: 640px) {
    h1 { font-size: 1.25rem; }
  }

  p, input, textarea {
    font-family: var(--font-sans);
    font-weight: 400;
    line-height: 1.75;
  }

  a {
    color: var(--text-primary);
    text-decoration: none;
    transition: color 0.15s;
  }

  *:focus-visible {
    outline: 2px solid var(--text-primary);
    outline-offset: 2px;
  }

  ::-webkit-scrollbar { width: 4px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }

  kbd {
    display: inline-flex;
    align-items: center;
    padding: 1px 5px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--bg-panel);
    font-family: var(--font-mono);
    font-size: 0.5625rem;
    color: var(--text-muted);
  }

  @media (max-width: 640px) {
    .kbd-hint { display: none; }
  }
}

@layer components {
  .page-container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 var(--sp-xl);
  }

  @media (max-width: 1024px) {
    .page-container { padding: 0 var(--sp-md); }
  }

  .editor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-md);
    align-items: stretch;
  }

  @media (max-width: 1024px) {
    .editor-grid { grid-template-columns: 1fr; }
  }

  .panel {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 380px;
  }

  .panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px var(--sp-md);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
  }

  .panel-label {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 5px;
  }

  .panel-label i {
    opacity: 0.6;
  }

  .panel-header-right {
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
  }

  .panel-body {
    flex: 1;
    padding: var(--sp-md);
    position: relative;
    z-index: 2;
  }

  .panel-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px var(--sp-md);
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-panel);
    flex-shrink: 0;
  }

  textarea {
    flex: 1;
    width: 100%;
    font-family: var(--font-sans);
    font-weight: 400;
    font-size: 0.9375rem;
    line-height: 1.75;
    color: var(--text-primary);
    background: transparent;
    padding: var(--sp-md);
    caret-color: var(--text-primary);
    border: none;
    outline: none;
    resize: none;
    transition: box-shadow 0.15s;
  }

  textarea:focus {
    box-shadow: inset 0 0 0 1.5px var(--border-strong);
  }

  textarea::placeholder {
    color: var(--text-muted);
  }

  .pill-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.8125rem;
    letter-spacing: 0.01em;
    padding: 8px 16px;
    border-radius: 99px;
    border: 1px solid var(--border-strong);
    background: transparent;
    color: var(--text-secondary);
    transition: all 0.15s;
    cursor: pointer;
    text-transform: uppercase;
  }

  .pill-btn:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
  }

  .pill-btn[aria-pressed="true"] {
    background: var(--text-primary);
    color: var(--bg-page);
    border-color: var(--text-primary);
  }

  .dark .pill-btn[aria-pressed="true"] {
    background: #fafafa;
    color: #09090b;
    border-color: #fafafa;
  }

  .pill-btn i {
    width: 13px;
    height: 13px;
  }

  .ghost-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.75rem;
    padding: 4px 12px;
    border-radius: 99px;
    border: 1px solid var(--border-strong);
    background: transparent;
    color: var(--text-secondary);
    transition: all 0.15s;
    cursor: pointer;
    display: none;
  }

  .ghost-btn.visible {
    display: inline-flex;
  }

  .ghost-btn:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
  }

  .ghost-btn.success {
    border-color: var(--color-success);
    color: var(--color-success);
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    border: none;
    background: transparent;
    color: var(--text-muted);
    transition: background 0.15s, color 0.15s;
    cursor: pointer;
  }

  .icon-btn:hover {
    background: var(--border-subtle);
    color: var(--text-primary);
  }

  .topbar {
    height: 52px;
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-topbar);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
  }

  .topbar > .topbar-inner {
    max-width: 1280px;
    margin: 0 auto;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--sp-xl);
  }

  @media (max-width: 1024px) {
    .topbar > .topbar-inner { padding: 0 var(--sp-md); }
  }

  .brand-block {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .brand-mark {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-md);
    background: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
  }

  .brand-mark svg {
    width: 15px;
    height: 15px;
    color: var(--bg-page);
  }

  .brand-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
  }

  .brand-name {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.8125rem;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    line-height: 1;
  }

  .brand-desc {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    line-height: 1;
  }

  .brand-pill {
    border: 1px solid var(--border-subtle);
    border-radius: 99px;
    padding: 2px 8px;
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.625rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    line-height: 1;
  }

  @media (max-width: 640px) {
    .brand-pill { display: none; }
  }

  .topbar-nav {
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
  }

  .topbar-link {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    padding: 6px 10px;
    border-radius: var(--radius-md);
    transition: background 0.15s, color 0.15s;
  }

  .topbar-link:hover {
    background: var(--border-subtle);
    color: var(--text-primary);
  }

  .hero-banner {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--sp-xl);
    margin-bottom: var(--sp-xl);
    flex-wrap: wrap;
  }

  @media (max-width: 1024px) {
    .hero-banner {
      flex-direction: column;
      align-items: flex-start;
      gap: var(--sp-md);
    }
  }

  .hero-controls {
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
  }

  @media (max-width: 640px) {
    .hero-controls { flex-wrap: wrap; }
  }

  main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: var(--sp-2xl) 0 var(--sp-xl);
  }

  @media (max-width: 1024px) {
    main { padding: var(--sp-xl) 0 var(--sp-md); }
  }

  footer {
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
  }

  footer > .footer-inner {
    max-width: 1280px;
    margin: 0 auto;
    width: 100%;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--sp-xl);
  }

  @media (max-width: 1024px) {
    footer > .footer-inner { padding: 0 var(--sp-md); }
  }

  .footer-nav {
    display: flex;
    align-items: center;
    gap: var(--sp-md);
  }

  .footer-link {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    transition: color 0.15s;
  }

  .footer-link:hover,
  .footer-link.active {
    color: var(--text-primary);
    border-bottom: 1px solid currentColor;
  }

  .footer-meta {
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 400;
    color: var(--text-muted);
  }

  .engine-badge {
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 400;
    color: var(--text-muted);
  }

  .locale-tag {
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
  }

  .locale-tag i {
    width: 11px;
    height: 11px;
  }

  .result-panel {
    position: relative;
  }

  .result-panel::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
      radial-gradient(ellipse 55% 55% at 10% 70%, rgba(0, 0, 0, 0.04) 0%, transparent 70%),
      radial-gradient(ellipse 35% 35% at 88% 18%, rgba(16, 185, 129, 0.04) 0%, transparent 60%);
  }

  .dark .result-panel::before {
    background:
      radial-gradient(ellipse 55% 55% at 10% 70%, rgba(255, 255, 255, 0.03) 0%, transparent 70%),
      radial-gradient(ellipse 35% 35% at 88% 18%, rgba(16, 185, 129, 0.04) 0%, transparent 60%);
  }

  .result-panel::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image: radial-gradient(circle, var(--border-subtle) 1px, transparent 1px);
    background-size: 22px 22px;
    opacity: 0.55;
  }

  .result-panel .panel-header,
  .result-panel .panel-footer {
    position: relative;
    z-index: 2;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .result-panel .panel-header {
    background: rgba(255, 255, 255, 0.6);
  }

  .dark .result-panel .panel-header {
    background: rgba(17, 17, 19, 0.6);
  }

  .result-panel .panel-footer {
    background: rgba(255, 255, 255, 0.6);
  }

  .dark .result-panel .panel-footer {
    background: rgba(17, 17, 19, 0.6);
  }

  .empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
    pointer-events: none;
  }

  .empty-state-circle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid var(--border-strong);
    background: var(--bg-surface);
    box-shadow: var(--shadow-md);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .empty-state-circle i {
    width: 18px;
    height: 18px;
  }

  @keyframes fadeUp {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .fade-in {
    animation: fadeUp 0.2s ease-out both;
  }

  @keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
  }

  .animate-pulse-custom {
    animation: pulse 1.5s ease-in-out infinite;
  }

  .topbar-right {
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
  }

  .topbar-left {
    display: flex;
    align-items: center;
    gap: 32px;
  }

  .topbar-link-group {
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
  }
  /* Logout text button — hidden by default, shown via .session-valid on .topbar */
  .logout-text-btn { display:none; font-family:var(--font-sans); font-weight:700; font-size:0.6875rem; text-transform:uppercase; letter-spacing:0.07em; color:var(--text-muted); background:transparent; border:none; cursor:pointer; padding:6px 10px; border-radius:var(--radius-md); transition:background .15s,color .15s; }
  .logout-text-btn:hover { background:var(--border-subtle); color:var(--text-primary); }
  .session-valid .logout-text-btn { display:inline-flex; }
  /* Dashboard project card grid */
  .project-grid { display:grid; grid-template-columns:repeat(auto-fill, minmax(300px, 1fr)); gap:var(--sp-md); }
  .project-card { background:var(--bg-surface); border:1px solid var(--border-subtle); border-radius:var(--radius-lg); box-shadow:var(--shadow-sm); display:flex; flex-direction:column; overflow:hidden; transition:box-shadow .2s; }
  .project-card:hover { box-shadow:var(--shadow-md); }
  .project-card-header { padding:var(--sp-lg) var(--sp-lg) 0; }
  .project-card-title { font-family:var(--font-sans); font-weight:900; font-size:0.8125rem; text-transform:uppercase; letter-spacing:-0.02em; color:var(--text-primary); margin:0 0 var(--sp-sm); }
  .project-card-body { padding:0 var(--sp-lg) var(--sp-lg); flex:1; }
  .project-card-desc { font-family:var(--font-sans); font-weight:400; font-size:0.8125rem; line-height:1.65; color:var(--text-secondary); margin:0; }
  .project-card-footer { padding:0 var(--sp-lg) var(--sp-lg); }
  .project-card-btn { display:inline-flex; align-items:center; gap:5px; font-family:var(--font-sans); font-weight:700; font-size:0.75rem; letter-spacing:0.01em; text-transform:uppercase; padding:7px 18px; border-radius:99px; border:1px solid var(--border-strong); background:transparent; color:var(--text-secondary); text-decoration:none; transition:all .15s; cursor:pointer; }
  .project-card-btn:hover { border-color:var(--text-primary); color:var(--text-primary); }
  @media (max-width:640px) { .project-grid { grid-template-columns:1fr; } }
  /* Footer — 3-column baseline grid: about/docs/status/privacy | brand | module filters + theme */
  .footer-3col { border-top:1px solid var(--border-subtle); flex-shrink:0; }
  .footer-3col > .footer-inner { display:grid; grid-template-columns:1fr auto 1fr; align-items:center; height:44px; max-width:1280px; margin:0 auto; width:100%; padding:0 var(--sp-xl); }
  .footer-left { display:flex; align-items:center; gap:var(--sp-md); }
  .footer-link { font-family:var(--font-sans); font-weight:700; font-size:0.6875rem; text-transform:uppercase; letter-spacing:0.08em; color:var(--text-muted); text-decoration:none; transition:color .15s; }
  .footer-link:hover, .footer-link.active { color:var(--text-primary); border-bottom:1px solid currentColor; }
  .footer-center { font-family:var(--font-sans); font-weight:700; font-size:0.6875rem; text-transform:uppercase; letter-spacing:0.08em; color:var(--text-muted); white-space:nowrap; }
  .footer-right { display:flex; align-items:center; gap:var(--sp-md); justify-content:flex-end; }
  .footer-right-divider { width:1px; height:16px; background:var(--border-subtle); }
  @media (max-width:640px) { .footer-3col > .footer-inner { grid-template-columns:1fr; height:auto; padding:var(--sp-sm) var(--sp-md); gap:var(--sp-xs); } }
  /* Metadata stamp — monospace version + timestamp below card grid */
  .meta-stamp { font-family:var(--font-mono); font-weight:400; font-size:0.625rem; color:var(--text-muted); margin-top:var(--sp-lg); text-align:center; letter-spacing:0.04em; }
}
