/* Fox Tales — brand colours live here so they're easy to change later. */
:root {
  --brand: #e8641b;
  --brand-dark: #b94a0c;
  --brand-soft: #fff1e8;
  --bg: #faf7f4;
  --surface: #ffffff;
  --text: #2a211c;
  --muted: #74675f;
  --border: #e6ddd5;
  --mine: #fde3d1;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: var(--brand);
  color: #fff;
}
.brand { color: inherit; text-decoration: none; font-size: 22px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.logo { font-size: 28px; }
.room-label { font-weight: 600; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.banner {
  background: #fff6d6;
  border-bottom: 1px solid #efd98a;
  padding: 8px 20px;
  font-size: 15px;
}

.screen { flex: 1; min-height: 0; }
.screen:not(.chat) { display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; }

.home { width: 100%; max-width: 960px; display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
.home .card { max-width: none; }
label.spaced { margin-top: 14px; }
a.button { display: block; text-align: center; text-decoration: none; }
.button-stack { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.button-stack > * { width: 100%; }
.screen#screenHome { flex-direction: column; align-items: center; justify-content: flex-start; }
.home-footer { margin: 28px 0 0; font-size: 15px; }
.home-footer a, .manage-back a, .manage-link { color: var(--muted); }
.manage-link { display: block; font-size: 15px; margin-bottom: 10px; }
.card.wide { max-width: 720px; }
.manage-back { margin: 20px 0 0 !important; font-size: 15px; }
.room-list { list-style: none; margin: 0 0 16px; padding: 0; border-top: 1px solid var(--border); }
.room-list li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.room-info { flex: 1; min-width: 0; }
.room-info a { color: var(--text); font-weight: 700; text-decoration: none; overflow-wrap: anywhere; }
.room-info a:hover { color: var(--brand-dark); text-decoration: underline; }
.room-meta { font-size: 14px; color: var(--muted); }
.room-list-status { color: var(--muted); }
button.danger.small { display: inline-block; width: auto; margin: 0; padding: 6px 14px; font-size: 15px; flex-shrink: 0; }
/* Rejoin and install cards on the home page */
.rejoin, .install {
  width: 100%; max-width: 960px; display: flex; align-items: center; gap: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 22px; box-shadow: 0 4px 18px rgba(80, 40, 10, 0.06);
}
.rejoin { margin-bottom: 24px; border: 2px solid var(--brand); justify-content: space-between; flex-wrap: wrap; }
.rejoin p { margin: 0; }
.rejoin-hello { font-size: 22px; font-weight: 700; }
.rejoin-sub { color: var(--muted); font-size: 16px; }
.rejoin .button { padding: 14px 22px; font-size: 18px; }
.install { margin-top: 24px; }
.install img { border-radius: 13px; flex-shrink: 0; }
.install-text { flex: 1; display: flex; flex-direction: column; gap: 2px; font-size: 16px; color: var(--muted); }
.install-text strong { color: var(--text); font-size: 18px; }
.install-actions { display: flex; flex-direction: column; align-items: center; gap: 6px; flex-shrink: 0; }
.install-actions button.primary { padding: 10px 22px; }
.share-icon { width: 18px; height: 18px; vertical-align: -3px; color: #0a84ff; }
.home-footer .link-button { font-size: 15px; vertical-align: baseline; }

.existed { background: var(--brand-soft); color: var(--brand-dark) !important; padding: 8px 12px; border-radius: 8px; }
button.primary.secondary { background: #fff; color: var(--brand-dark); border: 2px solid var(--brand); }
button.primary.secondary:hover { background: var(--brand-soft); }

.card {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 4px 18px rgba(80, 40, 10, 0.06);
}
.card h1 { margin: 0 0 8px; font-size: 28px; }
.card p { margin: 0 0 16px; color: var(--muted); }
label { display: block; font-weight: 600; margin-bottom: 6px; }

input, textarea {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}
input:focus, textarea:focus { outline: none; border-color: var(--brand); }

button { font: inherit; cursor: pointer; }
button.primary, a.button.primary {
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px 22px;
  font-weight: 700;
}
button.primary:hover, a.button.primary:hover { background: var(--brand-dark); }
button.primary:disabled { opacity: .5; cursor: default; }
form > button.primary { margin-top: 14px; width: 100%; }
.link-button { background: none; border: none; color: var(--brand-dark); text-decoration: underline; padding: 0; font-size: 15px; }

.link-box { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }
.link-row { display: flex; gap: 8px; }
.link-row input { font-size: 15px; }
.link-box a { color: var(--brand-dark); font-weight: 600; }

/* Chat layout */
.chat { display: flex; }
.people {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
}
.people h2 { font-size: 16px; margin: 0 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.people ul { list-style: none; margin: 0 0 16px; padding: 0; }
.people li { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 16px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #3cb371; flex-shrink: 0; }

.conversation { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.empty { margin: auto; color: var(--muted); text-align: center; }

.msg { max-width: min(640px, 85%); align-self: flex-start; }
.msg.mine { align-self: flex-end; }
.msg .meta { font-size: 14px; color: var(--muted); margin: 0 4px 2px; }
.msg .who { font-weight: 700; }
.msg.mine .meta { text-align: right; }
.msg .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.mine .bubble { background: var(--mine); border-color: transparent; }
/* The teacher's messages (marked by the database, so students can't fake it) */
.msg.from-teacher .bubble { background: var(--brand-soft); border: 2px solid var(--brand); }
.msg.from-teacher .who { color: var(--brand-dark); }
/* Dark orange behind white text for enough contrast (about 5:1), and no pixel nudging,
   which Safari and Chrome line up differently. */
.teacher-badge {
  display: inline-block; padding: 2px 9px; border-radius: 99px;
  background: var(--brand-dark); color: #fff;
  font-size: 13px; font-weight: 700; line-height: 1.35; letter-spacing: .03em;
  text-transform: uppercase; vertical-align: middle;
  -webkit-font-smoothing: antialiased;
}
.msg.pending .bubble { opacity: .6; }
.msg.failed .bubble { border-color: #d33; }
.bubble a { color: var(--brand-dark); }
.day { align-self: center; font-size: 13px; color: var(--muted); background: var(--border); padding: 2px 10px; border-radius: 99px; }

.teacher { margin-top: 24px; padding-top: 14px; border-top: 1px solid var(--border); }
.teacher h2 { margin-bottom: 8px; }
.teacher form { margin-top: 10px; }
.teacher label { font-size: 15px; }
.teacher input { padding: 8px 10px; font-size: 16px; }
.teacher button.primary.small { margin-top: 8px; width: 100%; padding: 8px 14px; font-size: 16px; }
.link-button.subtle { color: var(--muted); font-size: 14px; }
.error { color: #b3261e; font-size: 14px; margin: 6px 0 0; }
button.danger {
  display: block; width: 100%; margin-bottom: 10px;
  background: #fff; color: #b3261e; border: 2px solid #b3261e;
  border-radius: 10px; padding: 10px 14px; font-weight: 700;
}
button.danger:hover { background: #b3261e; color: #fff; }
button.danger:disabled { opacity: .5; }
.notice { padding: 6px 20px; font-size: 15px; background: var(--brand-soft); color: var(--brand-dark); text-align: center; }

/* File sharing */
.bubble.has-file { padding: 6px; }
.bubble.has-file .text { padding: 4px 8px 2px; }
.attachment.image { display: block; max-width: min(320px, 100%); color: var(--text); text-decoration: none; }
.attachment.image img { display: block; max-width: 100%; max-height: 260px; border-radius: 10px; background: var(--border); }
.attachment.image .file-info { padding: 6px 4px 0; }
.attachment.image:hover .file-meta { color: var(--brand-dark); }
.attachment.file {
  display: flex; align-items: center; gap: 10px; min-width: 220px; max-width: 360px;
  padding: 10px 12px; border-radius: 10px; background: rgba(255, 255, 255, .7);
  border: 1px solid var(--border); color: var(--text); text-decoration: none;
}
.attachment.file:hover { border-color: var(--brand); }
.file-icon { font-size: 28px; line-height: 1; flex-shrink: 0; }
.file-info { display: flex; flex-direction: column; min-width: 0; }
.file-name { font-weight: 600; overflow-wrap: anywhere; }
.file-meta { font-size: 13px; color: var(--muted); }
.composer button.attach {
  align-self: flex-end; flex-shrink: 0; width: 48px; height: 48px; font-size: 22px;
  background: var(--surface); border: 2px solid var(--border); border-radius: 10px;
}
.composer button.attach:hover { border-color: var(--brand); }
.upload { padding: 8px 20px; background: var(--brand-soft); font-size: 15px; }
.upload-text { display: flex; justify-content: space-between; gap: 12px; color: var(--brand-dark); }
#uploadName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-track { height: 6px; background: #fff; border-radius: 99px; margin-top: 4px; overflow: hidden; }
.upload-bar { height: 100%; width: 0; background: var(--brand); transition: width .2s; }
.conversation { position: relative; }
.conversation.dropping::after {
  content: "Drop the file to share it"; position: absolute; inset: 8px; display: flex;
  align-items: center; justify-content: center; font-size: 20px; font-weight: 700;
  color: var(--brand-dark); background: rgba(255, 241, 232, .92);
  border: 3px dashed var(--brand); border-radius: 14px; pointer-events: none;
}

.status { padding: 6px 20px; font-size: 15px; background: #ffe9e6; color: #8a1f11; }

.composer { display: flex; gap: 10px; padding: 12px 20px 16px; border-top: 1px solid var(--border); background: var(--surface); }
.composer textarea { resize: none; max-height: 160px; }
.composer > button.primary { align-self: flex-end; width: auto; margin-top: 0; flex-shrink: 0; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media (max-width: 760px) {
  .home { grid-template-columns: 1fr; gap: 16px; }
  .screen:not(.chat) { padding: 20px 16px; }
}

@media (max-width: 700px) {
  body { font-size: 17px; }
  .chat { flex-direction: column; }
  .people { width: auto; border-right: none; border-bottom: 1px solid var(--border); padding: 8px 16px; max-height: 140px; }
  .people ul { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-bottom: 4px; }
  .teacher { margin-top: 8px; padding-top: 8px; }
  .teacher button.danger { display: inline-block; width: auto; margin: 0 12px 0 0; padding: 6px 12px; }
  .messages { padding: 14px 16px; }
  .composer { padding: 10px 16px 12px; }
  .topbar { padding: 8px 16px; }
}

/* Phones with notches and home bars, especially when Fox Tales is installed as an app
   (the orange bar runs up behind the status bar). These only add space where a phone needs it. */
.topbar {
  padding-top: calc(10px + env(safe-area-inset-top));
  padding-left: calc(20px + env(safe-area-inset-left));
  padding-right: calc(20px + env(safe-area-inset-right));
}
.composer { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.screen:not(.chat) { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
@media (max-width: 700px) {
  .topbar {
    padding-top: calc(8px + env(safe-area-inset-top));
    padding-left: calc(16px + env(safe-area-inset-left));
    padding-right: calc(16px + env(safe-area-inset-right));
  }
  .composer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .screen:not(.chat) { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  .rejoin { padding: 16px; }
  .rejoin .button { width: 100%; }
  .install { flex-wrap: wrap; padding: 16px; }
  .install-actions { flex-direction: row; width: 100%; justify-content: flex-end; }
}
