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

body {
  font-family: 'Courier New', monospace;
  overflow-x: hidden;
  background-color: #1a1a1a;
  color: #333;
  position: relative;
  min-height: 100vh;
  padding-bottom: 360px; /* Space for fixed keyboard area */
}

/* Background Layer */
#background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  background:
    linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  opacity: 0.3;
}

#background::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 600"><defs><linearGradient id="bg1" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" style="stop-color:%23667eea;stop-opacity:0.1"/><stop offset="100%" style="stop-color:%23764ba2;stop-opacity:0.1"/></linearGradient></defs><polygon points="0,0 400,100 0,300" fill="url(%23bg1)"/><polygon points="800,0 400,200 800,400" fill="url(%23bg1)"/><polygon points="0,600 300,400 600,600" fill="url(%23bg1)"/><polygon points="800,600 500,400 800,300" fill="url(%23bg1)"/></svg>');
  background-size: cover;
  background-position: center;
  opacity: 0.5;
}

/* Page layout */
#layout {
  display: grid;
  grid-template-columns: 260px 1fr 260px;
  gap: 16px;
  padding: 20px 32px 20px 32px;
  align-items: flex-start;
}

#left-column {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: flex-start;
}

/* Controls */
#controls {
  background: rgba(255, 255, 255, 0.95);
  padding: 15px 20px;
  border-radius: 10px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  min-width: 280px;
  max-width: 280px;
}

#controls label {
  font-weight: bold;
  font-size: 14px;
  color: #333;
}

#sound-select {
  padding: 8px 12px;
  border: 2px solid #667eea;
  border-radius: 6px;
  background: white;
  font-family: 'Courier New', monospace;
  font-size: 14px;
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
  width: 100%;
}

#sound-select:hover {
  border-color: #764ba2;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

#sound-select:focus {
  border-color: #764ba2;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

/* Volume Controls */
#volume-controls {
  display: grid;
  grid-template-columns: auto 1fr 1fr 1fr;
  align-items: center;
  gap: 8px;
  margin-left: 0;
  padding-left: 0;
  border-left: none;
  border-top: 2px solid #ddd;
  padding-top: 10px;
  width: 100%;
}

#volume-controls label {
  font-weight: bold;
  font-size: 14px;
  color: #333;
}

.volume-btn {
  padding: 6px 10px;
  border: 2px solid #999;
  border-radius: 5px;
  background: white;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
  color: #666;
}

.volume-btn:hover {
  border-color: #667eea;
  background: #f0f0ff;
  color: #333;
}

.volume-btn.active {
  border-color: #667eea;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

.volume-btn:active {
  transform: scale(0.95);
}

/* Workspace Layout */
#workspace {
  display: flex;
  justify-content: center;
  min-height: calc(100vh - 360px);
}

/* Paper Container */
#paper-container {
  flex: 1;
  max-width: 1080px;
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: start;
  gap: 12px;
  padding: 0 16px;
}

#line-numbers {
  position: sticky;
  top: 0;
  padding: 40px 0;
  font-family: 'Courier New', monospace;
  font-size: 18px;
  line-height: 1.8;
  color: #999;
  text-align: right;
  user-select: none;
  pointer-events: none;
  width: 48px;
}

#paper {
  width: 100%;
  min-height: 500px;
  padding: 40px 40px 40px 40px;
  font-family: 'Courier New', monospace;
  font-size: 18px;
  line-height: 1.8;
  background: #fafafa;
  background-image:
    repeating-linear-gradient(
      transparent,
      transparent 31px,
      #e0e0e0 31px,
      #e0e0e0 32px
    );
  border: 1px solid #ccc;
  border-radius: 3px;
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  resize: none;
  outline: none;
  color: #1a1a1a;
  overflow-y: scroll;
  transition: box-shadow 0.3s ease;
  position: relative;
  z-index: 1;
}

#paper:focus {
  box-shadow:
    0 15px 40px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    0 0 0 3px rgba(102, 126, 234, 0.3);
}

#paper::placeholder {
  color: #aaa;
}

/* Help Pane */
#help-pane {
  width: 100%;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid #d6d6d6;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  padding: 18px;
  font-family: 'Courier New', monospace;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.help-header {
  margin-bottom: 12px;
}

.help-title {
  font-size: 18px;
  font-weight: bold;
  color: #222;
}

.help-subtitle {
  font-size: 13px;
  color: #666;
}

.help-body {
  background: linear-gradient(180deg, #fdfdfd 0%, #f5f5f7 100%);
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  padding: 12px;
}

#status-badge {
  min-height: 24px;
  font-size: 12px;
  color: #1a1a1a;
  background: rgba(255, 245, 158, 0.9);
  border: 1px solid #f0d34b;
  border-radius: 6px;
  padding: 6px 8px;
  display: none;
  margin-top: 4px;
}

#unicode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.control-chip {
  border: 1px solid #cfcfcf;
  border-radius: 6px;
  background: white;
  padding: 8px 10px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  transition: all 0.15s ease;
  width: 100%;
}

.control-chip strong {
  display: block;
  font-size: 14px;
}

.control-chip small {
  color: #666;
}

.control-chip:hover {
  border-color: #667eea;
  box-shadow: 0 2px 6px rgba(102, 126, 234, 0.25);
  transform: translateY(-1px);
}

.control-chip:active {
  transform: translateY(0);
}

#emoji-search {
  width: 100%;
  border: 2px solid #c7c7c7;
  border-radius: 6px;
  padding: 12px 12px;
  font-family: 'Courier New', monospace;
  font-size: 15px;
  background: linear-gradient(180deg, #fdfdfd 0%, #f0f0f0 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 2px 6px rgba(0, 0, 0, 0.1);
  color: #333;
}

#emoji-search:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.help-block {
  background: linear-gradient(180deg, #fdfdfd 0%, #f7f7f7 100%);
  border: 1px solid #e1e1e1;
  border-radius: 8px;
  padding: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 4px 10px rgba(0, 0, 0, 0.1);
}

.input-label {
  font-size: 13px;
  font-weight: bold;
  color: #444;
  display: block;
  margin-bottom: 6px;
}

.hint-text {
  font-size: 12px;
  color: #666;
  margin-top: 6px;
}

#help-name {
  font-size: 17px;
  font-weight: bold;
  margin-bottom: 6px;
}

#help-code {
  font-size: 13px;
  color: #555;
  margin-bottom: 10px;
}

#help-description {
  font-size: 14px;
  color: #333;
  margin-bottom: 12px;
  line-height: 1.4;
}

.help-example-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #777;
  margin-bottom: 6px;
}

#help-example {
  background: #1a1a1a;
  color: #f7f7f7;
  border-radius: 4px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}

/* Typewriter Keyboard */
#typewriter {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: linear-gradient(to bottom, #2a2a2a 0%, #1a1a1a 100%);
  padding: 16px 20px;
  box-shadow: 0 -5px 30px rgba(0, 0, 0, 0.5);
  z-index: 50;
}

#keyboard-area {
  display: grid;
  grid-template-columns: 280px 1fr 340px;
  gap: 16px;
  align-items: flex-start;
  max-width: 1420px;
  margin: 0 auto;
}

#keyboard-wrapper {
  position: relative;
  width: 100%;
}

#keyboard {
  width: 100%;
  max-width: 1200px;
  height: auto;
  justify-self: center;
}

#palette-panel {
  width: 320px;
  max-height: 360px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 60;
  background: transparent;
}

#formatting-pane {
  width: 100%;
  max-width: 280px;
  max-height: 360px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 60;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid #dcdcdc;
  border-radius: 10px;
  padding: 14px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.32);
}

.formatting-header .help-title {
  font-size: 16px;
}

#formatting-buttons {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.formatting-group-title {
  font-size: 12px;
  font-weight: bold;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #666;
  margin-top: 4px;
}

.formatting-btn {
  width: 100%;
  border: 1px solid #cfcfcf;
  border-radius: 8px;
  padding: 10px 12px;
  background: linear-gradient(180deg, #fdfdfd 0%, #f6f6f6 100%);
  text-align: left;
  font-family: 'Courier New', monospace;
  font-size: 15px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 3px 10px rgba(0, 0, 0, 0.14);
  transition: transform 0.08s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.formatting-btn:hover {
  border-color: #667eea;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.25);
  transform: translateY(-1px);
}

.formatting-btn:active {
  transform: translateY(0);
}

.formatting-label {
  font-size: 16px;
  font-weight: bold;
  line-height: 1.2;
  color: #1f1f1f;
}

.formatting-btn small {
  display: block;
  margin-top: 2px;
  color: #555;
  font-size: 12px;
}

.formatting-btn.disabled {
  opacity: 0.6;
  cursor: default;
  border-color: #d6d6d6;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 2px 6px rgba(0, 0, 0, 0.1);
}

.formatting-btn.disabled .formatting-label,
.formatting-btn.disabled small {
  opacity: 0.8;
}

.search-block {
  position: sticky;
  top: 0;
  z-index: 2;
}

.controls-block {
  padding-bottom: 16px;
}

#palette-panel .help-title {
  font-size: 16px;
  font-weight: bold;
}

/* SVG Keys */
.key {
  fill: url(#keyGradient);
  stroke: #999;
  stroke-width: 2;
  cursor: pointer;
  filter: drop-shadow(3px 3px 5px rgba(0, 0, 0, 0.4));
  transition: all 0.05s ease;
}

.key:hover {
  fill: #e8e8e8;
  filter: drop-shadow(2px 2px 3px rgba(0, 0, 0, 0.5));
}

.key.active {
  fill: url(#keyActiveGradient);
  filter: drop-shadow(1px 1px 2px rgba(0, 0, 0, 0.6));
  transform: translateY(2px);
}

.key-label {
  font-family: 'Courier New', monospace;
  font-size: 24px;
  font-weight: bold;
  fill: #333;
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: middle;
}

.key.inactive {
  fill: #ebebeb;
  cursor: default;
  filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.2));
}

.key.inactive + .key-label {
  fill: #b5b5b5;
}

/* Special key styles */
.key-space {
  fill: url(#keyGradient);
}

.key-enter {
  fill: url(#keyGradient);
}

.key-backspace,
.key-tab,
.key-caps,
.key-shift {
  fill: url(#keyGradient);
}

/* Active state for all keys */
.key.active + .key-label {
  fill: #1a1a1a;
}

/* Responsive Design */
@media (max-width: 1400px) {
  #keyboard {
    max-width: 1000px;
  }
}

@media (max-width: 1200px) {
  #keyboard {
    max-width: 900px;
  }

  #keyboard-area {
    grid-template-columns: 240px 1fr 280px;
  }

  #formatting-pane {
    max-width: 240px;
  }

  #palette-panel {
    width: 280px;
  }

  .key-label {
    font-size: 20px;
  }
}

@media (max-width: 900px) {
  #layout {
    grid-template-columns: 1fr;
    padding-bottom: 360px;
  }

  #left-column {
    position: relative;
    top: 0;
    width: 100%;
  }

  #paper {
    width: 95%;
    padding: 30px 35px;
    font-size: 16px;
  }

  #keyboard {
    max-width: 100%;
  }

  #keyboard-area {
    grid-template-columns: 1fr;
  }

  #formatting-pane,
  #palette-panel {
    max-width: 100%;
    width: 100%;
  }

  #formatting-pane {
    order: 1;
  }

  #keyboard-wrapper {
    order: 2;
  }

  #palette-panel {
    order: 3;
  }

  .key-label {
    font-size: 18px;
  }

  #palette-panel {
    width: 100%;
    max-height: none;
    margin-top: 12px;
  }
}

@media (max-width: 600px) {
  body {
    padding-bottom: 300px;
  }

  #paper {
    width: 95%;
    padding: 20px;
    font-size: 14px;
  }

  #typewriter {
    padding: 10px;
  }

  .key-label {
    font-size: 14px;
  }

  .volume-btn {
    padding: 5px 10px;
    font-size: 11px;
  }
}

/* Scrollbar Styling */
#paper::-webkit-scrollbar {
  width: 14px;
  background: transparent;
}

#paper::-webkit-scrollbar-track {
  background: #e8e8e8;
  border-radius: 0;
  border-left: 1px solid #d0d0d0;
}

#paper::-webkit-scrollbar-thumb {
  background: #a0a0a0;
  border-radius: 0;
  border: 2px solid #e8e8e8;
}

#paper::-webkit-scrollbar-thumb:hover {
  background: #808080;
}

#paper::-webkit-scrollbar-thumb:active {
  background: #606060;
}

/* Firefox scrollbar styling */
#paper {
  scrollbar-width: thin;
  scrollbar-color: #a0a0a0 #e8e8e8;
}

/* Animation for paper growth */
#paper {
  transition: height 0.2s ease-out;
}
