:root {
--bg: #000; --fg: #fff; --muted: #aaa; --line: #222; --accent: #fff;
--radius: 16px; --radius-sm: 12px; --radius-xs: 8px;
--shadow: 0 10px 30px rgba(255,255,255,0.03) inset, 0 10px 30px rgba(0,0,0,0.5);
--shadow-sm: 0 4px 12px rgba(0,0,0,0.3);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
margin: 0; background: var(--bg); color: var(--fg);
font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
min-height: 100vh;
min-height: 100dvh;
}
.container { 
width: min(900px, 100vw); 
padding: 0 clamp(12px, 4vw, 24px);
max-width: 100%;
margin: 0 auto;
padding-top: clamp(20vh, 25vh, 30vh);
}
.brand {
font-family: 'Playfair Display', Georgia, serif; font-weight: 600;
font-size: clamp(28px, 8vw, 42px); 
letter-spacing: 0.5px; 
text-align: center; 
position: absolute;
top: clamp(10vh, 15vh, 20vh);
left: 50%;
transform: translateX(-50%);
width: 100%;
line-height: 1.2;
margin-bottom: clamp(20px, 5vh, 32px);
}
.card {
border: 1px solid var(--line); 
border-radius: var(--radius); 
padding: clamp(16px, 4vw, 24px) clamp(14px, 4vw, 22px); 
background: #050505;
box-shadow: var(--shadow);
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.card h1, .card h2 { font-family: 'Playfair Display', Georgia, serif; margin: 0 0 16px; }
label { display: grid; gap: 6px; margin: 12px 0; font-size: 14px; color: #ddd; }
input, select, textarea {
background: #0b0b0b; 
color: var(--fg); 
border: 1px solid var(--line); 
border-radius: var(--radius-sm);
padding: clamp(10px, 3vw, 12px) clamp(12px, 3.5vw, 14px); 
font-size: clamp(14px, 3.5vw, 16px); 
outline: none;
transition: border-color 0.2s ease, background-color 0.2s ease;
-webkit-appearance: none;
touch-action: manipulation;
}
input:focus, select:focus, textarea:focus { 
border-color: #333; 
background: #111;
}
button {
appearance: none; 
background: var(--fg); 
color: var(--bg); 
border: none; 
border-radius: 999px;
padding: clamp(8px, 2.5vw, 10px) clamp(14px, 4vw, 16px); 
font-weight: 600; 
letter-spacing: .3px; 
cursor: pointer; 
margin-top: clamp(8px, 2vw, 10px);
font-size: clamp(14px, 3.5vw, 16px);
transition: all 0.2s ease;
touch-action: manipulation;
min-height: 44px;
outline: none;
}
button:hover, button:focus { 
transform: translateY(-1px); 
box-shadow: var(--shadow-sm);
}
button:focus {
box-shadow: var(--shadow-sm), 0 0 0 2px rgba(255,255,255,0.2);
}
button:active { 
transform: translateY(0); 
}
button.link { background: transparent; color: #fff; border: 1px solid var(--line); }
button.link:hover { background: #111; }
button.link:focus {
  border-color: #555;
  background: rgba(255,255,255,0.05);
  box-shadow: 0 0 0 2px rgba(255,255,255,0.1);
  transform: translateY(-1px);
}
.hint { color: var(--muted); font-size: 12px; margin-top: 10px; }
.status { font-size: 12px; color: var(--muted); margin-top: 8px; }
.tabs { 
display: flex; 
gap: clamp(6px, 2vw, 10px); 
align-items: center; 
margin: 0 0 clamp(12px, 3vw, 16px);
padding: clamp(8px, 2vw, 12px);
background: rgba(255,255,255,0.02);
border-radius: var(--radius-sm);
backdrop-filter: blur(10px);
overflow-x: auto;
scrollbar-width: none;
-webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button { 
  background: transparent; 
  color: #fff; 
  border: 1px solid var(--line); 
  height: clamp(36px, 8vw, 44px); 
  display: flex; 
  align-items: center; 
  padding: 0 clamp(10px, 3vw, 16px);
  margin-top: 0;
  box-sizing: border-box;
  font-size: clamp(12px, 3vw, 14px);
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.2s ease;
  min-width: 44px;
  outline: none;
}
.tabs button:focus {
  border-color: #555;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.1);
}
.tabs button:focus:not(.active) {
  background: rgba(255,255,255,0.05);
}
.tabs button.active { 
background: #fff; 
color: #000; 
transform: translateY(-1px);
box-shadow: var(--shadow-sm);
}
.tabs button:hover:not(.active) {
background: rgba(255,255,255,0.05);
border-color: #333;
}
.tabs .spacer { flex: 1; min-width: 8px; }
.badge { 
  border: 1px solid var(--line); 
  border-radius: 999px; 
  padding: 0 clamp(10px, 3vw, 16px); 
  font-size: clamp(11px, 2.5vw, 13px); 
  color: #ddd; 
  display: flex; 
  align-items: center; 
  height: clamp(36px, 8vw, 44px); 
  margin-right: clamp(6px, 2vw, 12px); 
  box-sizing: border-box;
  background: rgba(255,255,255,0.03);
  backdrop-filter: blur(5px);
  white-space: nowrap;
  flex-shrink: 0;
}

ul.letters { 
list-style: none; 
padding: 0; 
margin: 0; 
display: grid; 
gap: clamp(8px, 2vw, 12px);
width: 100%;
max-width: 100%;
overflow: hidden;
}
li.letter { 
border: 1px solid var(--line); 
border-radius: var(--radius-sm); 
padding: clamp(12px, 3vw, 16px); 
background: #0a0a0a; 
position: relative;
transition: all 0.3s ease;
backdrop-filter: blur(10px);
overflow: hidden;
word-wrap: break-word;
max-width: 100%;
}
li.letter:hover {
transform: translateY(-2px);
box-shadow: var(--shadow-sm);
border-color: #333;
}
.letter .meta { 
display: flex; 
gap: clamp(6px, 2vw, 10px); 
color: #bbb; 
font-size: clamp(11px, 2.5vw, 12px); 
margin-bottom: clamp(4px, 1vw, 6px); 
align-items: center; 
flex-wrap: wrap;
}
.letter .body { 
white-space: pre-wrap; 
line-height: 1.6; 
font-size: clamp(14px, 3.5vw, 16px);
word-wrap: break-word;
overflow-wrap: break-word;
hyphens: auto;
max-width: 100%;
overflow: hidden;
}
.letter .body.collapsed { 
  display: -webkit-box; 
  -webkit-line-clamp: 3; 
  -webkit-box-orient: vertical; 
  overflow: hidden; 
}
.letter .actions { 
display: flex; 
gap: clamp(6px, 2vw, 8px); 
margin-top: clamp(8px, 2vw, 12px); 
justify-content: flex-end; 
flex-wrap: wrap;
}
.letter .btn-small { 
  background: rgba(255,255,255,0.02); 
  color: #888; 
  border: 1px solid var(--line); 
  border-radius: var(--radius-xs); 
  padding: clamp(6px, 1.5vw, 8px) clamp(8px, 2vw, 12px); 
  font-size: clamp(10px, 2.5vw, 12px); 
  cursor: pointer; 
  transition: all 0.2s ease; 
  min-height: 32px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  backdrop-filter: blur(5px);
}
.letter .btn-small:hover, .letter .btn-small:focus { 
background: rgba(255,255,255,0.1); 
color: #fff; 
transform: translateY(-1px);
box-shadow: var(--shadow-sm);
}
.letter .btn-small:active { 
transform: translateY(0); 
}
.letter .btn-small.expand { 
color: #4a9eff; 
border-color: rgba(74, 158, 255, 0.3); 
background: rgba(74, 158, 255, 0.05);
}
.letter .btn-small.delete { 
color: #ff6b6b; 
border-color: rgba(255, 107, 107, 0.3); 
background: rgba(255, 107, 107, 0.05);
}
.letter .btn-small.delete:hover { 
background: rgba(255, 107, 107, 0.2); 
color: #fff; 
border-color: #ff6b6b;
}

.hidden { display: none; }

/* Tab content alignment */
.tab {
  min-height: 400px;
  transition: opacity 0.2s ease;
}

.tab .card {
  height: fit-content;
  min-height: 300px;
}

.tab .card h2 {
  margin-bottom: clamp(16px, 4vw, 20px);
}

.tab .card.list {
  min-height: 200px;
}

/* Ensure consistent spacing for all tabs */
#tab-compose, #tab-inbox, #tab-sent {
  display: flex;
  flex-direction: column;
}

#tab-compose.hidden, #tab-inbox.hidden, #tab-sent.hidden {
  display: none;
}

/* Mobile-specific optimizations */
@media (max-width: 768px) {
  .container {
    padding: 0 16px;
    padding-top: clamp(80px, 12vh, 120px);
  }
  
  .brand {
    font-size: clamp(24px, 7vw, 32px);
    position: static;
    transform: none;
    left: auto;
    top: auto;
    margin-bottom: clamp(20px, 4vh, 32px);
    margin-top: clamp(20px, 4vh, 32px);
  }
  
  .card {
    padding: 16px;
    border-radius: 12px;
  }
  
  .tabs {
    padding: 8px;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(20px);
    border: 1px solid var(--line);
  }
  
  .tabs button {
    font-size: 12px;
    padding: 0 12px;
    height: 40px;
  }
  
  .badge {
    font-size: 11px;
    padding: 0 12px;
    height: 40px;
    margin-right: 8px;
  }
  
  .letter .body {
    font-size: 15px;
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: anywhere;
    max-width: calc(100vw - 64px);
  }
  
  .letter .actions {
    margin-top: 12px;
    gap: 8px;
  }
  
  .letter .btn-small {
    padding: 8px 12px;
    font-size: 11px;
    min-height: 36px;
    min-width: 48px;
  }
  
  .tab {
    min-height: 300px;
  }
  
  .tab .card {
    min-height: 250px;
  }
}

/* Small mobile devices */
@media (max-width: 480px) {
  .container {
    padding: 0 12px;
    padding-top: clamp(60px, 10vh, 100px);
  }
  
  .brand {
    font-size: 24px;
    position: static;
    transform: none;
    left: auto;
    top: auto;
    margin-bottom: clamp(16px, 3vh, 24px);
    margin-top: clamp(16px, 3vh, 24px);
  }
  
  .card {
    padding: 12px;
    border-radius: 10px;
  }
  
  .tabs {
    padding: 6px;
    gap: 6px;
    margin-bottom: 12px;
  }
  
  .tabs button {
    font-size: 11px;
    padding: 0 10px;
    height: 36px;
  }
  
  .badge {
    font-size: 10px;
    padding: 0 10px;
    height: 36px;
    margin-right: 6px;
  }
  
  input, select, textarea {
    padding: 10px 12px;
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  button {
    padding: 10px 16px;
    font-size: 16px; /* Prevents zoom on iOS */
    min-height: 48px; /* Better touch target */
  }
  
  .letter .body {
    font-size: 14px;
    word-break: break-word;
    overflow-wrap: anywhere;
    max-width: calc(100vw - 48px);
  }
  
  .letter .btn-small {
    padding: 6px 10px;
    font-size: 10px;
    min-height: 32px;
    min-width: 44px;
  }
  
  .tab {
    min-height: 250px;
  }
  
  .tab .card {
    min-height: 200px;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  button:hover {
    transform: none;
    box-shadow: none;
  }
  
  button:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }
  
  .letter:hover {
    transform: none;
    box-shadow: none;
  }
  
  .tabs button:hover:not(.active) {
    background: transparent;
    border-color: var(--line);
  }
  
  .letter .btn-small:hover {
    background: rgba(255,255,255,0.02);
    transform: none;
    box-shadow: none;
  }
  
  .letter .btn-small:active {
    transform: scale(0.95);
  }
}

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

/* Dark mode support (already dark by default, but ensuring consistency) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000;
    --fg: #fff;
    --muted: #aaa;
    --line: #222;
  }
}
