* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  background: #0d1117;
  color: #c9d1d9;
  -webkit-text-size-adjust: 100%;
  display: flex;
  flex-direction: column;
}
.screen {
  flex: 1 1 auto;
  min-height: 0;
  padding-top: max(0.75rem, env(safe-area-inset-top));
  padding-right: max(0.75rem, env(safe-area-inset-right));
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  padding-left: max(0.75rem, env(safe-area-inset-left));
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.hidden { display: none !important; }
h1 { margin-top: 0; }
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #30363d;
  padding-bottom: 0.5rem;
}
form { display: flex; flex-direction: column; gap: 0.75rem; max-width: 320px; }
input, select, button {
  font-size: 16px;
  padding: 0.6rem;
  border-radius: 6px;
  border: 1px solid #30363d;
  background: #161b22;
  color: #c9d1d9;
}
button {
  background: #238636;
  color: white;
  cursor: pointer;
  border: none;
  font-weight: bold;
}
.error { color: #f85149; min-height: 1em; }
#status { display: flex; gap: 0.5rem; margin: 0.75rem 0; align-items: center; flex-wrap: wrap; }
#status select { flex: 1; min-width: 0; }
.badge { padding: 0.25rem 0.5rem; background: #21262d; border-radius: 4px; font-size: 0.85rem; }
#snapshot-section {
  flex: 1;
  min-height: 0;
  display: flex;
  margin: 0.5rem 0;
}
#snapshot {
  background: #010409;
  padding: 0.5rem;
  border-radius: 6px;
  white-space: pre;
  overflow-x: auto;
  overflow-y: auto;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  line-height: 1.25;
  flex: 1;
  min-height: 100px;
  -webkit-overflow-scrolling: touch;
  margin: 0;
  width: 100%;
}
#modbar {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.2rem;
  margin-top: 0.5rem;
}
.mod-btn {
  padding: 0.7rem 0.2rem;
  font-size: 1rem;
  background: #30363d;
  font-weight: 500;
}
#ctrl-toggle.active {
  background: #f85149;
  color: white;
}
#input-row {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
#kbd-input {
  flex: 1;
  min-width: 0;
}
#send-btn {
  padding: 0.6rem 1rem;
}
#quickkeys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.key-btn {
  padding: 0.9rem 0.2rem;
  font-size: 1rem;
}
textarea#kbd-input {
  flex: 1;
  min-width: 0;
  resize: none;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  line-height: 1.3;
  min-height: 2.5rem;
  max-height: 8rem;
  overflow-y: auto;
  padding: 0.6rem;
  border-radius: 6px;
  border: 1px solid #30363d;
  background: #161b22;
  color: #c9d1d9;
  caret-color: #58a6ff;
  -webkit-text-fill-color: #c9d1d9;
}
.cursor {
  outline: 1.5px solid rgba(201, 209, 217, 0.85);
  outline-offset: -1px;
  animation: cursorBlink 1s steps(2) infinite;
  border-radius: 1px;
}
@keyframes cursorBlink { 50% { outline-color: transparent; } }

.badge-btn {
  padding: 0.25rem 0.5rem;
  font-size: 1rem;
  border-radius: 4px;
  border: 1px solid #30363d;
  background: #21262d;
  color: #8b949e;
  cursor: pointer;
  font-weight: normal;
}
.badge-btn.active {
  background: #d29922;
  color: #0d1117;
  border-color: #d29922;
  box-shadow: 0 0 0 2px rgba(210, 153, 34, 0.25);
}

#new-session-row {
  display: flex;
  gap: 0.4rem;
  margin: 0.5rem 0 0;
  align-items: center;
  flex-wrap: wrap;
}
#new-session-name {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  padding: 0.6rem;
  border-radius: 6px;
  border: 1px solid #30363d;
  background: #161b22;
  color: #c9d1d9;
  caret-color: #58a6ff;
}
#new-session-create {
  padding: 0.6rem 0.9rem;
  white-space: nowrap;
}

textarea#kbd-input.live {
  border-color: #f85149;
  box-shadow: 0 0 0 1px rgba(248, 81, 73, 0.4);
}

@media (orientation: landscape) and (max-height: 500px) {
  #main-screen > header {
    display: none !important;
  }
  #main-screen .screen,
  .screen {
    padding-top: max(0.3rem, env(safe-area-inset-top));
    padding-bottom: max(0.3rem, env(safe-area-inset-bottom));
  }
  #status {
    margin: 0.25rem 0;
  }
}
