* { box-sizing: border-box; }
body {
  margin: 0;
  background: #d6d6c7;
  color: #111;
  font-family: "MS PGothic", "MS Gothic", Osaka, monospace;
  font-size: 14px;
  background-image: repeating-linear-gradient(0deg, rgba(255,255,255,.2) 0, rgba(255,255,255,.2) 1px, transparent 1px, transparent 4px);
}
a { color: #0000cc; }
a:visited { color: #660099; }
.page { width: min(920px, 96%); margin: 6px auto 22px; text-align: center; }
header { background: #ffffee; border: 3px ridge #aaa; padding: 6px 8px; }
h1 { color: #000080; font-size: 26px; margin: 8px 0 3px; text-shadow: 1px 1px #fff; }
.marquee { color: #cc0000; font-weight: bold; white-space: nowrap; overflow: hidden; }
.counter { font-size: 12px; }
.panel { margin-top: 12px; background: #eeeeee; border: 3px outset #ccc; padding: 14px; }
.join-panel { max-width: 580px; margin-left: auto; margin-right: auto; }
h2 { font-size: 18px; color: #800000; }
.form-table { margin: 10px auto; border-collapse: collapse; }
.form-table th, .form-table td { border: 1px solid #999; padding: 8px; text-align: left; background: #f8f8e8; }
.form-table th { background: #dcdcdc; }
input, select, button { font: inherit; }
input, select { border: 2px inset #ddd; background: white; padding: 5px; }
.retro-btn { border: 3px outset #ddd; background: #ddd; color: #000 !important; -webkit-text-fill-color: #000; padding: 4px 14px; cursor: pointer; }
.retro-btn:active { border-style: inset; }
.rules { text-align: left; background: #ffffdd; border: 1px dashed #999; padding: 10px; line-height: 1.7; }
.room-title { margin-top: 7px; padding: 5px; border: 2px ridge #bbb; background: #000080; color: white; font-weight: bold; }
.chat-layout { display: grid; grid-template-columns: 1fr 180px; gap: 8px; margin-top: 5px; text-align: left; align-items: stretch; }
.chat-main, .users-panel { border: 3px ridge #bbb; background: #f3f3e8; }
.chat-main { display: flex; flex-direction: column; min-height: 0; }
.messages { height: clamp(320px, 44dvh, 430px); overflow-y: auto; padding: 8px; background: #fffff5; border-bottom: 2px groove #aaa; line-height: 1.55; }
.msg { padding: 1px 0; overflow-wrap: anywhere; }
.msg:nth-child(odd) { background: rgba(0,0,0,.025); }
.msg.system { color: #666; text-align: center; font-style: italic; }
.time { color: #777; font-size: 12px; }
.send-form { display: grid; grid-template-columns: auto 1fr auto; gap: 6px; padding: 8px; align-items: center; }
.send-form input { width: 100%; }
.chat-links { text-align: center; padding: 0 8px 9px; font-size: 12px; }
.link-btn { border: 0; background: transparent; padding: 0; color: #0000cc; text-decoration: underline; cursor: pointer; }
.users-title { background: #800000; color: white; font-weight: bold; text-align: center; padding: 5px; }
.users-panel ul { list-style: none; margin: 8px; padding: 0; min-height: 120px; }
.users-panel li { padding: 3px 0; border-bottom: 1px dotted #bbb; }
.users-panel .small, .rom { padding: 6px; text-align: center; }
.rom { color: #006600; font-size: 12px; }
.small { font-size: 12px; }
footer { margin-top: 18px; font-size: 12px; color: #555; }

@media (max-width: 700px) {
  .chat-layout { grid-template-columns: 1fr; }
  .users-panel { order: -1; }
  .users-panel ul { min-height: 0; display: flex; flex-wrap: wrap; gap: 8px; }
  .users-panel li { border: 0; }
  .messages { height: clamp(240px, 40dvh, 340px); }
  .send-form { grid-template-columns: 1fr auto; }
  .send-form .who { grid-column: 1 / -1; }
}

/* iPhone / PWA */
body {
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  -webkit-text-size-adjust: 100%;
}
.install-hint {
  margin-top: 12px;
  text-align: left;
  background: #eaf4ff;
  border: 2px ridge #9ab;
  padding: 10px;
  line-height: 1.6;
}
@media (max-width: 700px) {
  body { font-size: 16px; }
  .page { width: 100%; margin: 0 auto 18px; padding: 6px; }
  header { padding: 7px 5px; }
  h1 { font-size: 22px; }
  .marquee { font-size: 12px; }
  .panel { padding: 10px; }
  .form-table { width: 100%; }
  .form-table th { width: 31%; }
  .form-table input, .form-table select { width: 100%; min-height: 44px; }
  .retro-btn { min-height: 44px; padding: 7px 14px; }
  .chat-layout { gap: 5px; }
  .users-panel { max-height: 112px; overflow-y: auto; }
  .users-panel ul { margin: 5px 8px; }
  .messages {
    height: clamp(220px, 38dvh, 320px);
    min-height: 220px;
    padding: 7px;
    -webkit-overflow-scrolling: touch;
  }
  .msg { padding: 3px 0; }
  .send-form { position: sticky; bottom: 0; background: #f3f3e8; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .send-form input { min-height: 46px; font-size: 16px; }
  .send-form button { min-width: 70px; }
  .chat-links { padding-bottom: 10px; }
}
@media (display-mode: standalone) {
  footer { padding-bottom: env(safe-area-inset-bottom); }
}
